获取已提交特定文件的贡献者列表

Sid*_*mal 3 javascript github-api

我正在寻找获取提交的作者/贡献者的方法。我对 github-api 真的很陌生,给我带来的麻烦比我想象的要多。

我们从..开始

  • 我有贡献者名单
  • ?author=我可以像这样在 github 网站上按贡献者过滤提交
  • 也可以在文件提交中看到贡献者 Github 显示文件的贡献者

应该是可以的

  • 所有这些让我觉得应该也可以通过 API 找到文件的贡献者。

问题描述

如果我有这样的文件的 URL ,是否有 github API 可以向我显示已提交该文件的贡献者列表?

或者,我是否需要使用多个 API 调用的结果(例如)

I'm thinking of cross-referencing the outputs of those two^ if everything else fails.

示例输出

应该返回 Pratik855


*编辑

我找到了这个答案,但这并不是我想要的。虽然满足了所有要求,但我不确定如何https://api.github.com/repos/csitauthority/csitauthority.github.io/commits?=README转换为https://api.github.com/repos/csitauthority/csitauthority.github.io/commits?=HUGO/content/page/vlan-101.md基于https://github.com/csitauthority/CSITauthority.github.io/blob/master/HUGO/content/post/vlan-101.md,因为 HUGO 只能生成第三种规范 URL。


我在用

  • 雨果
  • Github 页面

sid*_*ker 5

要获取存储库中特定文件的所有贡献者的完整数据,请调用
存储库端点上的 List commits,并将 file\xe2\x80\x99s 存储库路径作为path参数\xe2\x80\x99s 值:

\n

https://api.github.com/repos/csitauthority/CSITauthority.github.io/commits?path=HUGO/content/post/vlan-101.md

\n

也就是说,一般形式为:

\n
GET /repos/:owner/:repo/commits?path=:path-to-file\n
Run Code Online (Sandbox Code Playgroud)\n

\xe2\x80\x99 将返回一个 JSON 对象,其中包含该文件的所有提交的数组。要获取每个贡献者的姓名,您可以选择使用commit.author.namecommit.committer.name(取决于您真正想要的)或author.logincommitter.login

\n

因此,它\xe2\x80\x99 是一个API 调用\xe2\x80\x94,但要仅获取名称,请处理返回的JSON 数据。

\n

Here\xe2\x80\x99s 是一个在 JavaScript 中执行此操作的简单示例:

\n

\r\n
\r\n
GET /repos/:owner/:repo/commits?path=:path-to-file\n
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n

这里\xe2\x80\x99s 是一个如何跳过任何重复名称并以一组唯一名称结尾的示例:

\n

\r\n
\r\n
const githubAPI = "https://api.github.com"\nconst commitsEndpoint = "/repos/csitauthority/CSITauthority.github.io/commits"\nconst commitsURL = githubAPI + commitsEndpoint\nconst filepath = "HUGO/content/post/vlan-101.md"\nfetch(commitsURL + "?path=" + filepath)\n  .then(response => response.json())\n  .then(commits => {\n    for (var i = 0; i < commits.length; i++) {\n      console.log(commits[i].commit.author.name)\n    }\n  })
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n