【问题标题】:How to retrieve all the contributors of a repo using github api如何使用 github api 检索 repo 的所有贡献者
【发布时间】:2016-02-22 00:37:52
【问题描述】:

我正在尝试使用此github api 获取 repo 的所有贡献者。

如果我没记错的话,它还告诉我,如果一个 repo 的贡献者超过 500 个,它只给出 500 个,其余的标记为匿名。

出于性能原因,只有存储库中的前 500 个作者电子邮件地址会链接到 GitHub 用户。

这个 repo linux kernel 有 5k+ 贡献者,根据 api,我应该通过 api 获得至少 500 个贡献者。

当我做curl -I https://api.github.com/repos/torvalds/linux/contributors?per_page=100

我只得到 3 页 (per_page = 100),所以我得到 >300 个贡献者。(查看“链接”标题)

有没有办法获取所有 repo 的贡献者(5000+)?

HTTP/1.1 200 OK
Server: GitHub.com
Date: Thu, 19 Nov 2015 18:00:54 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 100308
Status: 200 OK
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 56
X-RateLimit-Reset: 1447958881
Cache-Control: public, max-age=60, s-maxage=60
Last-Modified: Thu, 19 Nov 2015 16:06:38 GMT
ETag: "a57e0f74fc68e1791da15d33fa044616"
Vary: Accept
X-GitHub-Media-Type: github.v3
Link: <https://api.github.com/repositories/2325298/contributors?per_page=100&page=2>; rel="next", <https://api.github.com/repositories/2325298/contributors?per_page=100&page=3>; rel="last"
X-XSS-Protection: 1; mode=block
X-Frame-Options: deny
Content-Security-Policy: default-src 'none'
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Content-Type-Options: nosniff
Vary: Accept-Encoding
X-Served-By: a30e6f9aa7cf5731b87dfb3b9992202d
X-GitHub-Request-Id: 67E881D2:146C9:24CF1BB3:564E0E55

【问题讨论】:

标签: java api curl github


【解决方案1】:

由于 GitHub API 似乎不支持这一点,另一种方法(慢得多的方法)是克隆存储库,然后运行此命令(获取名称):

git log --all --format='%aN' | sort -u

通过电子邮件地址获取结果(应防止贡献者名称配置更改并且更准确):

git log --all --format='%aE' | sort -u

如果您需要为任何 repo 提供此功能,您可以编写一个简单的脚本,该脚本将采用存储库路径,克隆 repo,运行命令,然后删除下载的 repo。

与此同时,您可以contact GitHub,希望他们提高扩展/修复 API 的优先级。

【讨论】:

  • 这比使用 GitHub API 慢很多。通过迭代贡献者列表有一个更好的方法。
  • @Whitecat 但是 Github API 没有所有的信息,那么这是目前唯一的方法。
猜你喜欢
  • 2015-08-30
  • 1970-01-01
  • 1970-01-01
  • 2017-03-31
  • 1970-01-01
  • 2022-01-27
  • 2017-11-18
  • 2014-10-14
  • 1970-01-01
相关资源
最近更新 更多