我想从 Azure DevOps 访问分析视图数据,以访问已注册的项目活动。
有人可以提供如何使用 azure-devops python 库来实现这一点的示例吗?
我没有找到涉及从分析视图提取数据的示例。基本上,我需要一个 Python 脚本来显示我项目的所有分析视图字段。
经过一番研究,我成功地部分解决了我的问题,因为这个解决方案并没有带来 Analytics View 中的所有内容,此外查询结果中有 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
"""
)
知道如何提取使用工作项字段创建的“查看”数据吗?
myProject/Boards/Analytics 视图 --> 新视图