【问题标题】:Get TFS code review comments report given for files获取为文件提供的 TFS 代码审查评论报告
【发布时间】:2017-06-16 14:44:39
【问题描述】:
        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.

【问题讨论】:

    标签: tfs


    【解决方案1】:

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

    具体来说,可以通过 DiscussionThread 类访问 cmets。只需使用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?

    【讨论】:

    • 感谢您的回复。我会检查您提供的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-10
    • 2020-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 2011-03-07
    相关资源
    最近更新 更多