2017-01-31 73 views
0
 We used TFS query option to get code review comments report, But 
we are not able to get TFS code review comments report given for files. 

     It is possible to get report by TFS query option/TFS REST API. 

enter image description here獲取給定的文件

Many thanks in advance. 

回答

2

無論工作項查詢也不休息API能夠檢索代碼審查意見,現在TFS代碼審查意見的報告。但是,您可以通過使用TFS API來實現您的目標。

具體的評論可以通過DiscussionThread類訪問。只需要使用IDiscussionManager查詢討論。 示例代碼如下:

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

更多詳細信息,請參閱此類似的問題:Using TFS API, how can I find the comments which were made on a Code Review?

+0

感謝您的答覆。我會檢查你提供的解決方案。 – Thulasiram