计算提交的代码更改行数?

Calculate lines of code change for a commit?

有没有办法在 Azure Devops 中为每个文件计算 Pull Request API 中的代码行数。我浏览了以下两个链接,但没有太大帮助。

Is there a way to get the amount of lines changed in a Pull Request via the Dev Ops Service REST API?

Lines of Code modified in each Commit in TFS rest api. How do i get?

谢谢。

步骤:

a. 获取指定拉取请求

commit IDs
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/commits?api-version=6.1-preview.1

b. 通过提交 ID

获取 commit path
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}/changes?api-version=5.0

c. 通过提交 ID

获取 parents commit ID
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}?api-version=5.0

d. 通过下面API 和请求正文获取结果。

POST https://dev.azure.com/{Org name}/_apis/Contribution/HierarchyQuery/project/{Project name}?api-version=5.1-preview

请求正文:

{
  "contributionIds": [
    "ms.vss-code-web.file-diff-data-provider"
  ],
  "dataProviderContext": {
    "properties": {
      "repositoryId": "{Repo ID}",
      "diffParameters": {
        "includeCharDiffs": true,
        "modifiedPath": "{Commit path}",
        "modifiedVersion": "GC{Commit ID}",
        "originalPath": "{Commit path}",
        "originalVersion": "GC{parents commit ID}",
        "partialDiff": true
      }
    }
  }
}

结果: