0

I am currently trying to retrieve all of the code reviews that are present in the "My Work" section of the Team Explorer window in Visual Studio. This is where it shows all code reviews you've created but haven't checked in yet as well as code reviews you've been requested to review but haven't yet. Looking through the documentation for the REST API, I am not able to find a method that will achieve this.

Curious if someone more knowledgeable with the API can help me out.

np_6
  • 514
  • 1
  • 6
  • 19
  • Have you checked my reply? Is it helpful? – Cece Dong - MSFT Aug 03 '20 at 07:13
  • @CeceDong-MSFT yeah it was definitely helpful! However the query you posted didn't return anything for me until I removed this where statement: `Source.[System.TeamProject] = @project`. Also I do not seem to be getting code reviews that people I requested I review, only ones I've created. Additionally, the main information I am trying to obtain from each code review is the number of comments and the approval status of each reviewers on the code review. Curious if you know this is possible to get? – user5924660 Aug 03 '20 at 23:55
  • To get all code review that I you are a reviewer, you need to add `[Target].[System.AssignedTo] = @me` clause, check my updated reply. Regarding comments, I'm afraid there is no REST API, you can check the client api as I replied in this case: https://stackoverflow.com/questions/61778434/get-code-review-comments-history-from-tfs-2018. If my reply helps you, please [Accept it as an Answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work), this can be beneficial to other community members reading this thread. – Cece Dong - MSFT Aug 04 '20 at 09:03

1 Answers1

1

You could use Wiql - Query By Wiql API like below to get the code reviews:

    POST https://dev.azure.com/{organization}/{project}/_apis/wit/wiql?api-version=5.1

# get all code review that I request 
    {
      "query": "SELECT [System.Id], [System.Links.LinkType], [System.Title], [System.State], [System.Reason], [System.AssignedTo] FROM WorkItemLinks WHERE (Source.[System.TeamProject] = @project and Source.[System.WorkItemType] in group 'Microsoft.CodeReviewRequestCategory' and Source.[System.AssignedTo] = @me and Source.[Microsoft.VSTS.Common.StateCode] <> '1') and ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') and (Target.[System.WorkItemType] in group 'Microsoft.CodeReviewResponseCategory') ORDER BY [System.CreatedDate] desc"
    }

# get all code review that I you are a reviewer
  
   {
      "query": "SELECT [System.Id], [System.Links.LinkType], [System.Title], [System.State], [System.Reason], [System.AssignedTo] FROM WorkItemLinks WHERE ([Source].[System.TeamProject] = @project  AND  [Source].[System.WorkItemType] IN GROUP 'Microsoft.CodeReviewRequestCategory'  AND  [Source].[Microsoft.VSTS.Common.StateCode] <> 1) And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') And ([Target].[System.WorkItemType] IN GROUP 'Microsoft.CodeReviewResponseCategory'  AND  [Target].[System.AssignedTo] = @me) ORDER BY [System.CreatedDate] desc"
   }
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • This is super helpful thanks! I noticed it also returns work item relations for people I've assigned the code review to like so: `{"rel": "System.LinkTypes.Hierarchy-Forward","source": {"id": 420905, "url": "http://dev-tfs:8080/tfs/HylandCollection/_apis/wit/workItems/420905" }, "target": { "id": 420906, "url": "http://dev-tfs:8080/tfs/HylandCollection/_apis/wit/workItems/420906" } }` Is it possible to just return the source work item? – user5924660 Aug 04 '20 at 15:56
  • Yes. You can get the code review you requested/created with the query: `SELECT [System.Id], [System.Title], [System.State], [System.Reason], [System.AssignedTo] FROM WorkItems WHERE [System.TeamProject] = @project AND [System.WorkItemType] IN GROUP 'Microsoft.CodeReviewRequestCategory' AND [Microsoft.VSTS.Common.StateCode] <> 1 AND [System.AssignedTo] = @me ORDER BY [System.CreatedDate] desc`. And you can get the code review that you are a reviewer by using `[System.WorkItemType] IN GROUP 'Microsoft.CodeReviewResponseCategory'`. – Cece Dong - MSFT Aug 05 '20 at 13:12