如何获取 Azure Devops 项目的所有工作项(Epics、功能、问题、任务、测试用例、用户故事等)?
How to get all work items(Epics, Features, Issue, Task, Test Case, User Story, etc) for an Azure Devops project?
我正在尝试获取所有工作项(Epics、功能、问题、任务、测试用例、用户故事等),然后使用 Microsoft azure devops python api 将它们分类为给定项目(又名 vsts)库。
在 work_item_tracking 我无法找到任何函数来获取 all 工作项或获取 all 工作项它的类型的基础。
是否已经有一个函数可以获取我找不到的所有工作项,或者我应该编写一个 WIQL 查询来获取所需的数据?
首先,我没有使用 python 库,但我可以告诉您必须使用哪些 API。
有一个API来检索所有work items。这只是一个具有所有工作项类型和属性的 JSON 对象。请注意,每个请求仅限于 200 个工作项。如果你想要更多的工作项,你必须编写一个 WIQL 查询。
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems?ids={ids}&api-version=5.0-preview.3
我个人建议您使用 WIQL 查询从 Azure DevOps 检索数据。它非常灵活,可以在任何情况下使用。
在这里您可以找到更多关于WIQL queries
的信息
在这里您可以找到关于Azure DevOps Rest API for WIQL Queries
的详细信息
Is there already a function for getting all work items that I am unable to find or should I write a WIQL query to fetch the required data?
你是对的。我们可以使用编写一个 WIQL 查询来获取系统 ID,然后我们可以根据 system.Ids 来查询工作项。以下是使用 python 代码获取所有工作项的演示代码。
from vsts.vss_connection import VssConnection
from msrest.authentication import BasicAuthentication
import json
from vsts.work_item_tracking.v4_1.models.wiql import Wiql
def emit(msg, *args):
print(msg % args)
def print_work_item(work_item):
emit(
"{0} {1}: {2}".format(
work_item.fields["System.WorkItemType"],
work_item.id,
work_item.fields["System.Title"],
)
)
personal_access_token = 'YourPATToken'
organization_url = 'https://dev.azure.com/YourorgName'
# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = VssConnection(base_url=organization_url, creds=credentials)
wiql = Wiql(
query="""select [System.Id] From WorkItems """
)
wit_client = connection.get_client('vsts.work_item_tracking.v4_1.work_item_tracking_client.WorkItemTrackingClient')
wiql_results = wit_client.query_by_wiql(wiql).work_items
if wiql_results:
# WIQL query gives a WorkItemReference with ID only
# => we get the corresponding WorkItem from id
work_items = (
wit_client.get_work_item(int(res.id)) for res in wiql_results
)
for work_item in work_items:
print_work_item(work_item)
更多demo代码可以参考这个link.
我正在关注这个 documentation 来实现它。
使用 Wiql 我们可以查询新版本的 Azure Devops 或 TFS。为了测试它,我使用 Postman 在实施之前使用服务。
第一步是使用 de 以下 url:
https://dev.azure.com/{organization}/{projectId}/_apis/wit/wiql?api-version=5.0
您必须使用以下 json 正文向 URL 发出 Post 请求以进行查询。检查下面的 json 负载。
{
"query": "Select [System.Id], [System.Title], [System.State], [System.WorkItemType] From WorkItems"
}
最后,如果请求正常,您将收到包含查询内容的 200 HTTP 响应,如果您收到错误,请求将出现错误描述和 HTTP 代码。
检查我在下面的回复 link 并检查返回请求的数据结构:
Result of my query
我正在尝试获取所有工作项(Epics、功能、问题、任务、测试用例、用户故事等),然后使用 Microsoft azure devops python api 将它们分类为给定项目(又名 vsts)库。
在 work_item_tracking 我无法找到任何函数来获取 all 工作项或获取 all 工作项它的类型的基础。
是否已经有一个函数可以获取我找不到的所有工作项,或者我应该编写一个 WIQL 查询来获取所需的数据?
首先,我没有使用 python 库,但我可以告诉您必须使用哪些 API。
有一个API来检索所有work items。这只是一个具有所有工作项类型和属性的 JSON 对象。请注意,每个请求仅限于 200 个工作项。如果你想要更多的工作项,你必须编写一个 WIQL 查询。
GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems?ids={ids}&api-version=5.0-preview.3
我个人建议您使用 WIQL 查询从 Azure DevOps 检索数据。它非常灵活,可以在任何情况下使用。
在这里您可以找到更多关于WIQL queries
的信息在这里您可以找到关于Azure DevOps Rest API for WIQL Queries
的详细信息Is there already a function for getting all work items that I am unable to find or should I write a WIQL query to fetch the required data?
你是对的。我们可以使用编写一个 WIQL 查询来获取系统 ID,然后我们可以根据 system.Ids 来查询工作项。以下是使用 python 代码获取所有工作项的演示代码。
from vsts.vss_connection import VssConnection
from msrest.authentication import BasicAuthentication
import json
from vsts.work_item_tracking.v4_1.models.wiql import Wiql
def emit(msg, *args):
print(msg % args)
def print_work_item(work_item):
emit(
"{0} {1}: {2}".format(
work_item.fields["System.WorkItemType"],
work_item.id,
work_item.fields["System.Title"],
)
)
personal_access_token = 'YourPATToken'
organization_url = 'https://dev.azure.com/YourorgName'
# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = VssConnection(base_url=organization_url, creds=credentials)
wiql = Wiql(
query="""select [System.Id] From WorkItems """
)
wit_client = connection.get_client('vsts.work_item_tracking.v4_1.work_item_tracking_client.WorkItemTrackingClient')
wiql_results = wit_client.query_by_wiql(wiql).work_items
if wiql_results:
# WIQL query gives a WorkItemReference with ID only
# => we get the corresponding WorkItem from id
work_items = (
wit_client.get_work_item(int(res.id)) for res in wiql_results
)
for work_item in work_items:
print_work_item(work_item)
更多demo代码可以参考这个link.
我正在关注这个 documentation 来实现它。
使用 Wiql 我们可以查询新版本的 Azure Devops 或 TFS。为了测试它,我使用 Postman 在实施之前使用服务。 第一步是使用 de 以下 url:
https://dev.azure.com/{organization}/{projectId}/_apis/wit/wiql?api-version=5.0
您必须使用以下 json 正文向 URL 发出 Post 请求以进行查询。检查下面的 json 负载。
{
"query": "Select [System.Id], [System.Title], [System.State], [System.WorkItemType] From WorkItems"
}
最后,如果请求正常,您将收到包含查询内容的 200 HTTP 响应,如果您收到错误,请求将出现错误描述和 HTTP 代码。
检查我在下面的回复 link 并检查返回请求的数据结构: Result of my query