首页 > 解决方案 > how to pull code review reports from TFSGIT

问题描述

I am trying to pull code review reports from the TFSGIT/VSTS, but I don't see anything out of the box. The 3rd part code review tools like "ReviewAssistant" works great but they are not integrated with the Pull Request. It decouples code review to pull request. I would like to get reports from the PullRequest code comments.

标签: tfspull-requesttfs-code-review

解决方案


You can pull data from TFS with Rest API.

To get the PR code comments you can use the Pull Request Threads - List.

The request is:

https://{instance}/{collection}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/threads?api-version=4.1

In the JSON response, you will get the comments and the comment location in the code (line number):

"comments": [
{
    "id": 1,
    "parentCommentId": 0,
    "author": {
    "displayName": "Shayki Abramczyk",
    "url": "https://spsprodweu3.vssps.visualstudio.com/Ac256a93d-7cea-4070-xxxxxxxxx/_apis/Identities/7a9a9b44-a2f1-6dfd-a7f6-xxxxxxxxxx",
    "_links": {
        "avatar": {
        "href": "https://dev.azure.com/xxxxxx/_apis/GraphProfile/MemberAvatars/msa.N2E5YTlxxxxxxxxxxxxxxx"
        }
    },
    "id": "7a9a9b44-a2f1-6dfd-a7f6-xxxxxxxxxx",
    "uniqueName": "xxxxxxxx",
    "imageUrl": "https://dev.azure.com/xxxxxxxx/_api/_common/identityImage?id=7a9a9b44-a2f1-6dfd-a7f6-xxxxxxxxxx",
    "descriptor": "msa.N2E5YTliNDQtYTJmMS03ZGZkLWE3Zjxxxxxxxxxxx"
    },
    "content": "test comment",
    "publishedDate": "2019-02-25T11:11:03.45Z",
    "lastUpdatedDate": "2019-02-25T11:11:03.45Z",
    "lastContentUpdatedDate": "2019-02-25T11:11:03.45Z",
    "commentType": "text",
    "usersLiked": [

    ]
}
],
"status": "active",
"threadContext": {
"filePath": "/SampleForVSTS/Program.cs",
"leftFileStart": {
    "line": 14,
    "offset": 1
},
"leftFileEnd": {
    "line": 14,
    "offset": 10
}
},

As you can see there is a comment test comment at line 14 in the file SampleForVSTS/Program.cs.

You can write simple code in any language to get the data with Rest API.


推荐阅读