如何从 TFSGIT 中提取代码审查报告

how to pull code review reports from TFSGIT

我正在尝试从 TFSGIT/VSTS 中提取代码审查报告,但我没有看到任何现成的东西。 第三部分代码审查工具,如 "ReviewAssistant" 效果很好,但它们没有与 Pull Request 集成。它将代码审查与拉取请求分离。 我想从 PullRequest 代码评论中获取报告。

您可以使用 Rest API 从 TFS 中提取数据。

要获取 PR 代码注释,您可以使用 Pull Request Threads - List

请求是:

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

在JSON响应中,你会得到注释和注释在代码中的位置(行号):

"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
}
},

如您所见,文件 SampleForVSTS/Program.cs.

的第 14 行有注释 test comment

您可以使用任何语言编写简单的代码来使用 Rest 获取数据 API。