Search code examples
tfstfs-code-review

Using TFS API, how can I find the status of code review like "Looks Good", "Needs work"?


I searched the discussions already and have tried this,

Changeset changeSet = _versionControlServer.GetChangeset(Int32.Parse(changesetString));
                            if (changeSet != null)
                            {


                                foreach (var item in changeSet.AssociatedWorkItems)
                                {
                                    WorkItem wk = workItemStore.GetWorkItem(item.Id);

But I cannot find a public property from WorkItem that says "Finished(Looks Good)".

Is there a way to find this through the API?


Solution

  • There are two types of work items comes to code reviews: Code Review Request ,Code Review Response.

    When you ask for a review, TFS creates a Code Review Request, and then behind the scenes creates one Code Review Response for every person you’ve asked to review my work. So if you tag Alice, Bob, and Charlie on my review, there are four work items created for me: one request plus three responses.

    The glue is something called a Related Link. The parent review relates to the children responses and vice versa. This simplifies things a bit because once you have the review, you can easily determine the response work items based on their IDs.

    The code you are trying to get the work item is Code Review Request. What you want to find is a filed called Closed Status in Code Review Response:

    The status selected by the reviewer when closing the code review request. The number is stored in the system and written to the data warehouse as follows:

    • 0 – Not Reviewed
    • 1 - Looks Good
    • 2 - With Comments
    • 3- Needs Work
    • 4 - Declined
    • 5 - Removed

    Reference name=Microsoft.VSTS.CodeReview.ClosedStatus

    Source Link

    You could use WIQL combine with TFS API to fetch what you need. Details steps please refer this tutorial: Getting Code Review Statistics Programmatically from TFS

    More example of accessing code reviews with TFS API is shown here: Using TFS API, how can I find the comments which were made on a Code Review?