I am using TFS 2018 On Premise.
Is there any way to get the list of review comments (like shown in Visual studio) using api or using TFS query.
I am using TFS 2018 On Premise.
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:
You should be able to get to code review comments with functionality in the Microsoft.TeamFoundation.Discussion.Client namespace.
Specifically the comments are accessible via the DiscussionThread class. And you should be able to query discussions using IDiscussionManager.
Code snippet is as below:
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; }
}
}
}