通过休息从 devops 获取所有工作项 api

Get all work items from devops throug rest api

根据文档,您可以获得如下工作项:

GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems?ids={ids}&api-version=5.1

但是您需要为所有需要的工作项提供 ID。如果您只想要所有工作项怎么办?如果我跳过 ID,我会得到以下信息:

Response status code does not indicate success: 404 (Not Found).


好的,多亏了一些回复,我离得更近了:

var uri = "https://dev.azure.com/xx"; 
var personalAccessToken = "xx";
var project = "GAC";

VssBasicCredential credentials = new VssBasicCredential("", personalAccessToken);

Wiql wiql = new Wiql()
{
    Query = "Select [State], [Title],[Remaining Work] From WorkItems Where [Work Item Type] = 'Bug' OR [Work Item Type] = 'Task' And [System.TeamProject] = '" + project+"'"
};

//create instance of work item tracking http client
using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(new Uri(uri), credentials))
{
    //execute the query to get the list of work items in the results
    WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;

    //some error handling                
    if (workItemQueryResult.WorkItems.Count() != 0)
    {
        foreach (IEnumerable<WorkItemReference> batch in workItemQueryResult.WorkItems.Batch(100))
        {
            var workItemIds = batch.Select(p => p.Id).ToArray();
            var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(workItemIds, expand: WorkItemExpand.All).Result;
        }                   
    }              
}

但是我没有得到关于我主要寻找的东西的信息,例如已完成的、剩余的作品等。有任何指示吗?

您需要创建查询以编程方式获取工作项。

检查:https://docs.microsoft.com/en-us/azure/devops/integrate/quickstarts/work-item-quickstart?view=azure-devops#create-a-c-project-in-visual-studio

除了核心系统字段外,这些字段非常依赖于所使用的流程模板(敏捷、Scrum 等)。您甚至可以拥有自定义字段。 那么如何找出名称,或者更具体地说,ReferenceName,以便查询呢?

            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
        {
            List<WorkItemField> fieldsQuery = await workItemTrackingHttpClient.GetFieldsAsync(_project, null, null, System.Threading.CancellationToken.None);

            if (fieldsQuery.Count() != 0)
            {
                foreach (var fieldItem in fieldsQuery)
                {
                    Console.WriteLine("{0} / {1}", fieldItem.Name, fieldItem.ReferenceName);
                }
            }
        }

您没有正确填写 "Remaining Work" 字段,您应该给出字段引用名称而不是标签。

剩余工作的参考名称是:Microsoft.VSTS.Scheduling.RemainingWork

因此在您的查询中使用它:

Query = "Select [System.Id], [System.State]. [System.Title], [Microsofy.VSTS.Scheduling.RemainingWork] FROM ..."

您可以在此 url (api) 中看到所有字段及其引用名称:

https://dev.azure.com/{your-organization-name}/_apis/wit/fields