【发布时间】:2020-05-13 15:22:09
【问题描述】:
【问题讨论】:
标签: tfs azure-devops azure-devops-rest-api azure-devops-server-2019
【问题讨论】:
标签: tfs azure-devops azure-devops-rest-api azure-devops-server-2019
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; }
}
}
}
【讨论】: