使用 GitHub 的 API 获取每次提交(在分支上)的代码行 added/deleted?

Using GitHub's API to get lines of code added/deleted per commit (on a branch)?

以下获取项目 master 分支的原始提交列表:

https://api.github.com/repos/<organization_name>/<repo_name/commits?page=0&per_page=30

问题 1:除了特定的 <branchname>,如何获得类似的列表?

问题 2: 上面的提交列表不包含有关每次提交的代码行数 added/deleted 的任何数据(即非常粗略的生产力指标) .有没有办法在查询中获取这些数据?

您可以在 /commits 参数中使用 sha={branchname} 参数获取特定分支;

sha string SHA or branch to start listing commits from. Default: the repository’s default branch (usually master).

https://api.github.com/repos/<org_name>/<repo_name>/commits?sha=<branchName>&page=0&per_page=30

要获得每个提交的 per-file 特定更改,您需要检查上述 URL 响应中每个提交实体的 url 变量。从 new endpoint call 中,您将获得有关该单个提交的更详细信息。 files 中的变量将包含该提交中包含的更改。每个文件都添加和删除了代码。

An example with my repo;

https://api.github.com/repos/buraequete/orikautomation/commits?sha=master&page=0&per_page=30

If we get the first commits url;

https://api.github.com/repos/buraequete/orikautomation/commits/89792e6256dfccc5e9151d81bf04145ba02fef8f

Which contains the changes you want in files variable as a list.

"files": [
    {
      "sha": "8aaaa7de53bed57fc2865d2fd84897211c3e70b6",
      "filename": "lombok.config",
      "status": "added",
      "additions": 1,
      "deletions": 0,
      "changes": 1,
      "blob_url": "https://github.com/buraequete/orikautomation/blob/89792e6256dfccc5e9151d81bf04145ba02fef8f/lombok.config",
      "raw_url": "https://github.com/buraequete/orikautomation/raw/89792e6256dfccc5e9151d81bf04145ba02fef8f/lombok.config",
      "contents_url": "https://api.github.com/repos/buraequete/orikautomation/contents/lombok.config?ref=89792e6256dfccc5e9151d81bf04145ba02fef8f",
      "patch": "@@ -0,0 +1 @@\n+lombok.accessors.chain = true"
    },
    ...
]

抱歉,但我认为没有办法在原始 /commits 端点调用中获取每个文件的更改,您必须进行多次调用...