不管是哪个项目,我想知道获取单个用户名所有公共仓库提交记录的简单方法。
由于我属于多个组织,我试图编制一个列表,其中包括我是贡献者的项目以及我已接受拉取请求的项目。
到目前为止,我的Google搜索和查看GitHub API文档的尝试都没有成功。
不管是哪个项目,我想知道获取单个用户名所有公共仓库提交记录的简单方法。
由于我属于多个组织,我试图编制一个列表,其中包括我是贡献者的项目以及我已接受拉取请求的项目。
到目前为止,我的Google搜索和查看GitHub API文档的尝试都没有成功。
https://connectionrequired.com/gitspective是你的好帮手。 :-) 只需过滤掉除“Push”之外的所有内容,你就可以得到你想要的视图,尽管没有编写代码实现它的工作。
检查Chrome DevTools“Network”选项卡中发生的内容可能会帮助你模仿API查询,如果你想自己重新执行这项工作。
GET /users/:username/events
type
设置为PushEvent
)。每个这样的项目对应于用户的一个git push
。该推送的提交以相反的时间顺序在payload.commits
数组中可用。author.email
属性来过滤其他用户所做的提交。您还可以在同一对象上访问诸如sha
、message
和url
等属性,并使用distinct
属性消除多个推送之间的重复提交。
编辑:正如Adam Taylor在评论中指出的那样,这种方法是错误的。我没有仔细阅读手册,很抱歉。API允许您获取最多300个事件,并且事件也限制在过去90天内。我会将答案保留在这里以保证完整性,但对于获取所有提交的声明问题,它不起作用。更新 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
...
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
}
}
}
}
}
organization_repositories
和list_repositories
服务(我正在使用octokit)找到用户贡献的所有潜在存储库。branches
),并针对每个分支仅查找来自我们的用户的提交(服务commits
)。OBS: As pointed out, this solution does not consider organizations and repositories where you contributed but are not part of.
您可以使用API方法get-a-single-user获取有关用户的信息。
之后,您可以使用类似以下函数的功能找到所有用户存储库,然后提交:
def get_github_email(user_login, user_name, key):
'''
:param str user_login: user login for GitHub
:param str key: your client_id + client_secret from GitHub,
string like '&client_id=your_id&client_secret=yoursecret'
:param str user_name: user GitHub name (could be not equeal to user_login)
:return: email (str or None) or False
'''
url = "https://api.github.com/users/{}/repos?{}".format(user_login, key)
#get repositories
reps_req = requests.get(url)
for i in reps_req.json():
if "fork" in i:
# take only repositories created by user not forks
if i["fork"] == False:
commits_url = "https://api.github.com/repos/{}/{}/commits?{}".format(user_login, i["name"], key)
#get commits
commits_req = requests.get(commits_url)
for j in commits_req.json():
#check if author is user (there may be commits from someone else)
if j.get("commit", {}).get("author", {}).get("name") == user_name:
return j["commit"]["author"]["email"]
return False