【问题标题】:GitHub api to obtain last N number of commits获取最后 N 次提交的 GitHub api
【发布时间】:2016-08-09 21:19:18
【问题描述】:

是否可以使用 GitHub API 获得对 GitHub 存储库中特定分支的最后 N 次提交?

我刚刚发现了一些关于提交 here 的 GitHub api 详细信息,但没有一个提供有关最后 N 次提交的详细信息!

任何人都可以对此提供更好的想法吗?

另外,是否可以在用户上次提交期间识别更改的文件类型?

【问题讨论】:

  • 你试过pagination吗?您可以使用它限制每页的项目。
  • @Andrew:非常感谢您的解决方案!但是这个解决方案的唯一问题是,我得到的只是列表的顶部。即它不是最后 N 次提交。这是我尝试过的命令,curl -i https://api.github.com/repos/technoweenie/fantomex/commits?per_page=2 ... 是否有任何选项可以对我们从此 api 获得的提交列表进行排序?
  • 关注parameterssha: SHA or branch to start listing commits from. Default: the repository’s default branch (usually master). 您可以尝试使用 URL https://api.github.com/repos/technoweenie/fantomex/commits?per_page=2&sha=branch_name 来仅检索相关的提交。
  • 我也找到了 sorting & order 的参数。我已根据最新更改修改了我之前的查询:curl -i https://api.github.com/repos/technoweenie/fantomex/commits?sort=created&order=desc ..但它本身仍然显示相同的输出..!这有什么毛病吗??我从here获得了有关排序和排序的详细信息
  • 你试过我之前评论中的 url 吗?还是不是你想要的吗?

标签: github github-api


【解决方案1】:

你可以试试这个Github API 来获取最后 N 次提交,

输入:

GIT_REPO="https://api.github.com/repos/kubernetes/kubernetes" # Input Git Repo
BRANCH_NAME="master"                                          # Input Branch Name
COMMITS_NUM="5"                                               # Input to get last "N" number of commits

curl --silent --insecure --request GET --header "Accept: application/vnd.github.inertia-preview+json" "$GIT_REPO/commits?sha=$BRANCH_NAME&page=1&per_page=1000" | jq --raw-output '.[] | "\(.sha)|\(.commit.author.date)|\(.commit.message)|\(.commit.author.name)|\(.commit.author.email)" | gsub("[\n\t]"; "")' | awk 'NF' | awk '{$1=$1;print}' | head -$COMMITS_NUM

输出:

COMMIT_ID|DATE/TIME|COMMIT_MESSAGE|AUTHOR_NAME|AUTHOR_EMAIL
5ed4b76a03b5eddc62939a1569b61532b4a06a72|2020-11-26T15:24:19Z|Merge pull request #96421 from dgrisonnet/fix-apiservice-availabilityFix aggregator_unavailable_apiservice gauge|Kubernetes Prow Robot|k8s-ci-robot@users.noreply.github.com
c1f36fa6f28d3618c03b65799bc3f58007624e5f|2020-11-25T06:32:41Z|Merge pull request #96829 from songjiaxun/azuredisk_api_versionfix: change disk client API version for Azure Stack|Kubernetes Prow Robot|k8s-ci-robot@users.noreply.github.com
c678434623be4957d892a9865e5649f887a40c49|2020-11-24T21:20:39Z|Merge pull request #96831 from bobbypage/vendor-cadvisor-v0_38_5vendor: update cAdvisor to v0.38.5|Kubernetes Prow Robot|k8s-ci-robot@users.noreply.github.com
c652ffbe4a29143623a1aaec39f745575f7e43ad|2020-11-24T14:59:01Z|Merge pull request #96636 from Nordix/disable-nodeport-2service.spec.AllocateLoadBalancerNodePorts followup|Kubernetes Prow Robot|k8s-ci-robot@users.noreply.github.com
4a46efb70701ee00028723ecb137e401d83be4f4|2020-11-24T07:45:19Z|vendor: update cAdvisor to v0.38.5|David Porter|david@porter.me

注意:

1.确保您已安装jq 以获取所需格式的输出并根据您的要求解析 json 密钥。

2.确保在“curl”命令中更新Git Repo Url。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    • 2015-07-02
    • 1970-01-01
    • 2020-12-31
    相关资源
    最近更新 更多