获取为文件提供的TFS代码审查评论报告

时间:2017-01-31 08:31:36

标签: tfs tfs2013

        We used TFS query option to get code review comments report, But 
we are not able to get TFS code review comments report given for files.

        It is possible to get report by TFS query option / TFS REST API.

enter image description here

    Many thanks in advance.

1 个答案:

答案 0 :(得分:2)

工作项查询和休息API目前都无法检索代码审核注释。但是,您可以使用 TFS API 来实现目标。

具体而言,可以通过DiscussionThread课程查看评论。只需要使用IDiscussionManager查询讨论。 示例代码如下:

 public List<CodeReviewComment> GetCodeReviewComments(int workItemId)
 {
        List<CodeReviewComment> comments = new List<CodeReviewComment>();

        Uri uri = new Uri(URL_TO_TFS_COLLECTION);
        TeamFoundationDiscussionService service = new TeamFoundationDiscussionService();
        service.Initialize(new Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(uri));
        IDiscussionManager discussionManager = service.CreateDiscussionManager();

        IAsyncResult result = discussionManager.BeginQueryByCodeReviewRequest(workItemId, QueryStoreOptions.ServerAndLocal, new AsyncCallback(CallCompletedCallback), null);
        var output = discussionManager.EndQueryByCodeReviewRequest(result);

        foreach (DiscussionThread thread in output)
        {
            if (thread.RootComment != null)
            {
                CodeReviewComment comment = new CodeReviewComment();
                comment.Author = thread.RootComment.Author.DisplayName;
                comment.Comment = thread.RootComment.Content;
                comment.PublishDate = thread.RootComment.PublishedDate.ToShortDateString();
                comment.ItemName = thread.ItemPath;
                comments.Add(comment);
            }
        }

        return comments;
    }

    static void CallCompletedCallback(IAsyncResult result)
    {
        // Handle error conditions here
    }

    public class CodeReviewComment
    {
        public string Author { get; set; }
        public string Comment { get; set; }
        public string PublishDate { get; set; }
        public string ItemName { get; set; }
    }

更多详情请参阅此类似问题:Using TFS API, how can I find the comments which were made on a Code Review?