【问题标题】:Calculate lines of code change for a commit? [closed]计算提交的代码更改行数? [关闭]
【发布时间】:2021-04-06 19:59:03
【问题描述】:

有没有办法在 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?

谢谢。

【问题讨论】:

  • 为什么你需要知道这个?更改的代码行数不是衡量任何事情的可靠指标。
  • 只是另一个要求:(

标签: c# api azure-devops pull-request


【解决方案1】:

步骤:

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

结果:

【讨论】:

  • 谢谢你,我会尝试从主存储库而不是提交之间获取差异。任何帮助将不胜感激。另外,在拉取请求中,假设有 20 次提交,我只需要获取最终提交版本和主版本之间的差异。
  • 嗨@AjayVerma,你的意思是列出所有不同之处吗?如果你能在 UI 中得到它,你能在这里分享截图结果吗?我们可以通过 F12 获得它。
  • 嗨,是的。我的意思是 [最终迭代文件,即迭代计数为 2](GET dev.azure.com{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/iterations/2/changes? api-version=6.0) 这为我们提供了更改条目。在您的屏幕截图中,就像它在主分支和当前分支详细信息之间显示 -2 和 +3 一样。
猜你喜欢
  • 2016-09-29
  • 1970-01-01
  • 2018-03-13
  • 1970-01-01
  • 2013-01-22
  • 2013-05-25
  • 2011-02-01
相关资源
最近更新 更多