栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Python REST API从VSTS(Azure DevOps)中的查询中提取工作项?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Python REST API从VSTS(Azure DevOps)中的查询中提取工作项?

在VSTS示例的Github存储库中发布了一条消息(即导致请求请求的问题)之后,我得到了解决问题的提示。

解决方案是使用:

  • 一个带有
    Wiql
    类的wiql查询对象
  • query_by_wiql
    功能
  • 将查询结果(具有WorkItem ID的引用)转换为具有
    get_work_item
    功能的WorkItem (或
    get_work_items
    通过一次处理处理多个WorkItem)

这是我对这个问题的解决方案:

[针对版本5.1和azure-devops模块进行了更新,以取代VSTS]

from azure.devops.connection import Connectionfrom msrest.authentication import BasicAuthenticationfrom azure.devops.v5_1.work_item_tracking.models import Wiqltoken = "hcykwckuhe6vbnigsjs7r3ai2jefsdlkfjslkfj5mxizbtfu6k53j4ia"team_instance = "https://tfstest.toto.com:8443/tfs/Development/"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)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/647423.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号