tfs - 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.
解决方案
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.
推荐阅读
- postgresql - Sequelize 不会创建唯一约束
- c++ - 使用经常调用的 api 实现 C++ 多客户和生产者解决方案,这行得通吗?
- ios - Swift IOS,匿名用户+安全
- node.js - 从 Google Maps API 调用获取 node.js 证书链中的自签名证书
- html - 如何使此文本可选?
- javascript - 使用 jquery 在不同的场景下点击显示所有项目
- arrays - C ++ 11中的可变长度数组
- javascript - 如何通过 RxJS 6 制作 SR Latch?
- c# - 使用 Asp.Net MVC 处理临时会话数据
- sed - 如何查找字符串并附加(不安全)文本?