GitHub api获取最后N次提交

时间:2016-04-18 08:25:38

标签: github github-api

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

我刚刚发现了很少有关于提交here的GitHub api详细信息,但是他们都没有提供有关最近N次提交的详细信息!

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

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

1 个答案:

答案 0 :(得分: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。

相关问题