从TFS 2018获取代码审查注释历史记录 [英] Get Code Review comments history from TFS 2018

查看:79
本文介绍了从TFS 2018获取代码审查注释历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在内部使用TFS 2018.

I am using TFS 2018 On Premise.

是否可以使用api或使用TFS查询获取评论评论列表(如Visual Studio中所示).

Is there any way to get the list of review comments (like shown in Visual studio) using api or using TFS query.

推荐答案

This case provides a solution, you can check it:

您应该能够使用 Microsoft.TeamFoundation.Discussion.Client 名称空间.

You should be able to get to code review comments with functionality in the Microsoft.TeamFoundation.Discussion.Client namespace.

具体而言,可以通过访问注释.DiscussionThread 类.而且您应该能够使用 IDiscussionManager来查询讨论.

Specifically the comments are accessible via the DiscussionThread class. And you should be able to query discussions using IDiscussionManager.

代码段如下:

using Microsoft.TeamFoundation.Discussion.Client;
using System;
using System.Collections.Generic;

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

            Uri uri = new Uri("http://tfs2018:8080/tfs/defaultcollection");
            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);
                    Console.WriteLine(comment.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 2018获取代码审查注释历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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