Azure开发人员/运营人员使用Python摄取分析视图数据

2024-05-15 23:01:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从Azure DevOps访问分析视图数据,以访问已注册的项目活动

有没有人能举例说明他们将如何使用azure devops python库来实现这一点

我没有发现从Analytics视图中提取数据的示例。基本上,我需要一个Python脚本来显示我的项目的所有分析视图字段


Tags: 数据项目脚本视图示例azureanalyticsdevops
1条回答
网友
1楼 · 发布于 2024-05-15 23:01:30

经过一些研究,我设法部分解决了我的问题,因为该解决方案并没有从分析角度提供所有信息,此外,查询结果中有20k条记录的限制:

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.v5_1.work_item_tracking.models import Wiql


token = 'xxx'
team_instance = 'https://dev.azure.com/xxx'


credentials = BasicAuthentication("", token)
connection = Connection(base_url=team_instance, creds=credentials)


def print_work_items(work_items):
    for work_item in work_items:
        print(
            "{0} {1}: {2}".format(
                work_item.fields["System.WorkItemType"],
                work_item.id,
                work_item.fields["System.Title"],
            )
        )


wit_client = connection.clients.get_work_item_tracking_client()


def get_TC_from_query(query):
    query_wiql = Wiql(query=query)
    results = wit_client.query_by_wiql(query_wiql).work_items
    # WIQL query gives a WorkItemReference => we get the corresponding WorkItem from id
    work_items = (wit_client.get_work_item(int(result.id)) for result in results)
    print_work_items(work_items)

get_TC_from_query(
    """\
SELECT
        [System.Id],
        [System.WorkItemType],
        [System.Title],
        [System.State],
        [System.AreaPath],
        [System.IterationPath]
FROM workitems
WHERE
        [System.TeamProject] = 'Project'
        and [System.WorkItemType] = 'Product Backlog Item'
        and [System.State] = 'Done'
ORDER BY [System.ChangedDate] DESC
"""
)    

相关问题 更多 >