如何获取用户的所有公共github提交

mar*_*ert 30 github github-api

无论项目如何,我都想知道是否有一种简单的方法可以为所有公共存储库提供单个用户名的所有提交.

由于我属于多个组织,我正在尝试编译我作为贡献者的项目列表,以及我已接受拉取请求的项目.

到目前为止,我的google-fu和浏览github api docs证明是不够的.

ecm*_*aut 20

http://zmoazeni.github.com/gitspective/是你的朋友.:-)过滤除"推"之外的所有内容,你有了自己的观点,尽管没有编码工作,你自己先实现它.

如果您想自己重做工作,检查Chrome Devtools"网络"选项卡的内容可能会帮助您模拟API查询.

  • 这不是**所有**贡献.它只显示今年的所有情况,而不是2011年以来. (8认同)

Phi*_*oth 11

执行此操作的正确方法是通过Events API.

首先,您需要获取用户的事件:

GET /users/:username/events
Run Code Online (Sandbox Code Playgroud)

然后,你将要过滤的项目响应数组,其中type设置为PushEvent.这些项中的每一项对应于git push用户的a.来自该推送的提交在payload.commits阵列中以反向时间顺序提供.

下一步是通过检查author.email每个提交对象的属性来过滤掉其他用户提交的提交.您还可以使用类似的属性sha,messageurl在同一对象上,并且可以消除通过在多个推重复提交distinct财产.

编辑:正如Adam Taylor在评论中指出的那样,这种做法是错误的.我没能通过RTFM,抱歉.API允许您获取最多300个事件,事件也仅限于过去90天.为了完整起见,我将在这里留下答案,但是对于提取所有提交的所述问题,它将无效.


Aur*_*ien 5

更新 2018-11-12

下面提到的 URL 现在已经移动到一个单一的 URL,看起来像https://github.com/AurelienLourot?from=2018-10-09但想法保持不变。请参阅github-contribs


我想知道是否有一种简单的方法可以为单个用户名获取所有公共存储库的所有提交。

第一个挑战是列出用户曾经贡献过的所有存储库。正如其他人所指出的,官方 API从一开始就不允许您获取此信息。

您仍然可以通过查询非官方页面并在循环中解析它们来获取该信息:

(免责声明:我是维护者。)

这正是github-contribs为您所做的:

$ sudo npm install -g @ghuser/github-contribs
$ github-contribs AurelienLourot
? Fetched first day at GitHub: 2015-04-04.
? Be patient. The whole process might take up to an hour... Consider using --since and/or --until
? Fetched all commits and PRs.
35 repo(s) found:
AurelienLourot/lsankidb
reframejs/reframe
dracula/gitk
...
Run Code Online (Sandbox Code Playgroud)


Bar*_*row 5

GitGub GraphQL API v4 ContributionsCollection对象提供按两个日期之间的存储库分组的贡献,最多 100 个存储库。from并且to最多可以相隔一年,因此要检索所有贡献,您将需要提出多个请求。

query ContributionsView($username: String!, $from: DateTime!, $to: DateTime!) {
  user(login: $username) {
    contributionsCollection(from: $from, to: $to) {
      commitContributionsByRepository(maxRepositories: 100) {
        repository {
          nameWithOwner
        }
        contributions {
          totalCount
        }
      }
      pullRequestContributionsByRepository(maxRepositories: 100) {
        repository {
          nameWithOwner
        }
        contributions {
          totalCount
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)