GitHub API获取最近N次提交 [英] GitHub api to obtain last N number of commits

查看:85
本文介绍了GitHub API获取最近N次提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to obtain last N number of commits to a particular branch in a GitHub repository using GitHub API ?

我只是在此处中找到了一些有关GitHub api的细节,但没有一个他们中的人提供了有关最后N次提交的详细信息!

I just found few GitHub api details regarding the commits here, but none of them are giving details about last N number of commits!

任何人都可以对此提供更好的主意吗?

Anyone can provide a better idea about this ?

还可以在用户的​​最后一次提交期间识别更改的文件类型吗?

Also, Is it possible to identify the changed file type during the last commit from a user ?

推荐答案

您可以尝试

You can try this Github API to get the last N number of commits,

输入:

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键,按您的要求.

1.Make sure you have installed jq to get output in the desired format and parse json key as per your requirement.

2.确保在"curl"窗口中更新Git Repo Url.命令.

2.Make sure to update the Git Repo Url in "curl" command.

这篇关于GitHub API获取最近N次提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆