获取为文件给出的 TFS 代码审查意见报告 [英] Get TFS code review comments report given for files

查看:21
本文介绍了获取为文件给出的 TFS 代码审查意见报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        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.

    Many thanks in advance.

推荐答案

Work item query 和 rest API 目前都无法检索代码审查评论.但是,您可以通过使用 TFS API 来实现您的目标.

Neither Work item query nor rest API is able to retrieve code review comments for now. However you can achieve your goal by using TFS API.

特别是可以通过访问评论DiscussionThread 类.只需要使用 IDiscussionManager.示例代码如下:

Specifically the comments are accessible via the DiscussionThread class. Just need to query discussions using IDiscussionManager. Sample code as below:

 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; }
    }

更多细节请参考这个类似的问题:使用 TFS API,我如何找到对代码审查所做的评论?

More details please refer this similar question: Using TFS API, how can I find the comments which were made on a Code Review?

这篇关于获取为文件给出的 TFS 代码审查意见报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆