【问题标题】:Get Code Review comments history from TFS 2018 [duplicate]从 TFS 2018 获取 Code Review 评论历史记录 [重复]
【发布时间】:2020-05-13 15:22:09
【问题描述】:

我正在使用 TFS 2018 On Premise。

有没有办法使用 api 或使用 TFS 查询来获取评论 cmets 列表(如 Visual Studio 中所示)。

【问题讨论】:

    标签: tfs azure-devops azure-devops-rest-api azure-devops-server-2019


    【解决方案1】:

    This case提供了解决方案,可以查看:

    您应该能够使用 Microsoft.TeamFoundation.Discussion.Client 命名空间中的功能进行代码审查 cmets。

    具体来说,可以通过 DiscussionThread 类访问 cmets。您应该可以使用IDiscussionManager 查询讨论。

    代码sn-p如下:

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

    【讨论】:

    • 感谢董策的回复。我已经用 .net core conole 应用程序尝试过这个。包括 "Microsoft.TeamFoundationServer.Client" Version="16.153.0" 和 "Microsoft.TeamFoundationServer.ExtendedClient" Version="16.153.0" 但它们都没有帮助解决 Microsoft.TeamFoundation.Discussion.Client。
    • 你可以试试 .net 框架控制台应用程序,它会工作的。
    • 好的,非常感谢,我会尝试使用 .net 框架。我想知道我们有没有 .net core 的 nuget 包?
    • 包 "Microsoft.TeamFoundationServer.ExtendedClient" 与 .net 核心不兼容。有些功能可以在 .net 核心应用程序中使用,但有些不能。所以建议改用.net framework app。
    • 非常感谢@Cece。感谢您的时间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 2019-08-23
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多