0

I am trying to retrive the review comments for all my code reviews fromthe TFS. I am not able to build the query. My parameters are as below. I do not get anything from this :-(

Team Project = @Project
And    Work Item Type     In Group    Code Review Response Category
And    Requested By          =        @Me
Or     Requested By       Was Ever    @Me

Thanks

Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
App
  • 346
  • 3
  • 9

1 Answers1

0

Work item query is not able to retrieve code review comments, you can achieve your goal by using TFS API. 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:

 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; }
    }
Community
  • 1
  • 1
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39