【发布时间】:2017-12-10 12:08:33
【问题描述】:
我想知道在从 Github API 创建某个分支之前完成了多少次提交。
例如在 git cli 中我正在做:git log --no-merges --oneline ${branchHash} | wc -l,我可以看到数字。
Github API 有 100 个限制,所以如果我有超过 100 个提交,我就无法全部获得。
这种情况有什么解决办法吗?
【问题讨论】:
标签: git github github-api
我想知道在从 Github API 创建某个分支之前完成了多少次提交。
例如在 git cli 中我正在做:git log --no-merges --oneline ${branchHash} | wc -l,我可以看到数字。
Github API 有 100 个限制,所以如果我有超过 100 个提交,我就无法全部获得。
这种情况有什么解决办法吗?
【问题讨论】:
标签: git github github-api
我写了一个小东西来解决这个问题:
Gist "Easy way to calculate commits count from the GitHub API"。
它基于使用GitHub Commit API的compare URL,并使用total_commits字段:
compare_url = '{}/repos/{}/{}/compare/{}...{}'.format(base_url, owner, repo, first_commit, sha)
commit_count = commit_req.json()['total_commits'] + 1
【讨论】:
为了避免执行多个查询,您可以使用GraphQL one,类似于this one 或this one:它将获取给定分支的所有提交,以便您计算它们。
{
repository(name: "sickvim", owner: "jonathansick") {
ref(qualifiedName: "master") {
target {
... on Commit {
id
history(first: 5) {
pageInfo {
hasNextPage
}
edges {
node {
oid
}...
【讨论】:
{ "data": null, "errors": [ { "message": "Requesting 101 records on the connection exceeds the `first` limit of 100 records." } ] }
{ repository(name: "sickvim", owner: "jonathansick") { ref(qualifiedName: "master") { target { ... on Commit { id history(first: 101) { pageInfo { hasNextPage } edges { node { messageHeadline oid message author { name email date } } } } } } } } }