简体   繁体   English

如何使用 Azure DevOps / VSTS 获取 python 中的查询结果

[英]How to use Azure DevOps / VSTS to fetch query results in python

Below is my current code.以下是我当前的代码。 It connects successfully to the organization.它成功连接到组织。 How can I fetch the results of a query in Azure like they have here ?我怎样才能像他们在这里一样获取 Azure 中的查询结果? I know this was solved but there isn't an explanation and there's quite a big gap on what they're doing.我知道这已经解决了,但没有解释,而且他们正在做的事情还有很大的差距。

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

personal_access_token = 'xxx'
organization_url = 'zzz'

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)

wit_client = connection.clients.get_work_item_tracking_client()

results = wit_client.query_by_id("my query ID here")

PS Please don't link me to the github or documentation . PS 请不要将我链接到github文档 I've looked at both extensively for days and it hasn't helped.几天来,我已经广泛研究了这两种方法,但没有帮助。

Edit: I've added the results line that successfully gets the query.编辑:我添加了成功获取查询的结果行。 However, it returns a WorkItemQueryResult class which is not exactly what is needed.但是,它返回一个 WorkItemQueryResult class,这并不完全是需要的。 I need a way to view the column and results of the query for that column.我需要一种方法来查看该列的查询结果。

So I've figured this out in probably the most inefficient way possible, but hope it helps someone else and they find a way to improve it.所以我已经以可能最低效的方式解决了这个问题,但希望它可以帮助其他人并且他们找到改进它的方法。

The issue with the WorkItemQueryResult class stored in variable "result" is that it doesn't allow the contents of the work item to be shown.存储在变量“result”中的 WorkItemQueryResult class 的问题是它不允许显示工作项的内容。

So the goal is to be able to use the get_work_item method that requires the id field, which you can get (in a rather roundabout way) through item.target.id from results' work_item_relations.所以目标是能够使用需要id字段的get_work_item方法,您可以通过item.target.id从结果的 work_item_relations 中获取(以一种相当迂回的方式)。 The code below is added on.添加下面的代码。

for item in results.work_item_relations:
   id = item.target.id
   work_item = wit_client.get_work_item(id)
   fields = work_item.fields

This gets the id from every work item in your result class and then grants access to the fields of that work item, which you can access by fields.get("System.Title" ), etc.这会从结果 class 中的每个工作项中获取 id,然后授予对该工作项字段的访问权限,您可以通过fields.get("System.Title" ) 等访问该工作项的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM