使用 TFS 查找哪些工作项是代码审查 API

Find which WorkItems are Code Reviews using the TFS API

给定工作项列表,我想使用 C# 中的 TFS 2015 API 找到与代码审查对应的实例。

虽然我可以从描述的文本中看出 WorkItem 是否是代码审查,但我更愿意避免解析该字符串并依赖更可靠的东西(例如:WorkItem.Type)...

你会怎么做(Type 值对我来说似乎很神秘)?

您可以使用以下方法获取工作项的类型。但是您需要提供工作项 ID。

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

        Uri collectionUri = (args.Length < 1) ?
            new Uri("http://servername:8080/tfs/MyCollection") : new Uri(args[0]);

        // Connect to the server and the store. 
        TfsTeamProjectCollection teamProjectCollection =
           new TfsTeamProjectCollection(collectionUri);

         WorkItemStore workItemStore = teamProjectCollection.GetService<WorkItemStore>();
        string queryString = "Select [State], [Title],[Description] From WorkItems Where [Work Item Type] = 'Code Review Request' or [Work Item Type] = 'Code Review Response'";

        // Create and run the query.
        Query query = new Query(workItemStore, queryString);
        WorkItemCollection witCollection = query.RunQuery();

        foreach (WorkItem workItem in witCollection)
        {
            workItem.Open();
            Console.WriteLine(workItem.Fields["Title"].Value.ToString());

        }