使用 TFS API,如何找到 "Looks Good"、"Needs work" 等代码审查的状态?

Using TFS API, how can I find the status of code review like "Looks Good", "Needs work"?

我已经搜索过讨论并尝试过这个,

Changeset changeSet = _versionControlServer.GetChangeset(Int32.Parse(changesetString));
                            if (changeSet != null)
                            {


                                foreach (var item in changeSet.AssociatedWorkItems)
                                {
                                    WorkItem wk = workItemStore.GetWorkItem(item.Id);

但我无法从 WorkItem 中找到 public 属性 "Finished(Looks Good)"。

有没有办法通过 API 找到这个?

代码审查有两种类型的工作项目:代码审查请求 ,代码审查响应

When you ask for a review, TFS creates a Code Review Request, and then behind the scenes creates one Code Review Response for every person you’ve asked to review my work. So if you tag Alice, Bob, and Charlie on my review, there are four work items created for me: one request plus three responses.

The glue is something called a Related Link. The parent review relates to the children responses and vice versa. This simplifies things a bit because once you have the review, you can easily determine the response work items based on their IDs.

您尝试获取工作项的代码是代码审查请求。您想要查找的是代码审查响应中名为 Closed Status 的文件:

The status selected by the reviewer when closing the code review request. The number is stored in the system and written to the data warehouse as follows:

  • 0 – Not Reviewed
  • 1 - Looks Good
  • 2 - With Comments
  • 3- Needs Work
  • 4 - Declined
  • 5 - Removed

Reference name=Microsoft.VSTS.CodeReview.ClosedStatus

Source Link

您可以结合使用 WIQL 和 TFS API 来获取您需要的内容。详细步骤请参考本教程:Getting Code Review Statistics Programmatically from TFS

此处显示了使用 TFS API 访问代码审查的更多示例:Using TFS API, how can I find the comments which were made on a Code Review?

对于任何需要它的人,

 foreach (WorkItem wr in workitems)
            {

            string shelvsetValue = null;
            string codeState = null;
            string userName = wr.CreatedBy.ToString();
            foreach(Field f in wr.Fields)
            {
                if(f.Name.Equals("Associated Context"))
                {
                    shelvsetValue = f.Value.ToString();
                }
                if (f.Name.Equals("Closed Status Code"))
                {
                    if(f.Value!=null)
                    { 
                        codeState = f.Value.ToString();
                    }
                }
            }