是否有一个GitLab API来获取特定分支的提交计数?
我可以使用以下curl命令获取分支的提交,但不能获取提交计数。
curl -X GET -H "PRIVATE-TOKEN: <my_private_token>" "http://<my_locally_hosted_web_server>/api/v4/projects/2/repository/commits/?ref_name=master"
答案 0 :(得分:1)
获取页面数(另请参见gitlab pagination),并使用jq遍历计数json数组元素的页面:
TOTAL_PAGES=$(curl -Ss -k --head --header "PRIVATE-TOKEN: <my_private_token>" "http://<my_locally_hosted_web_server>/api/v4/projects/2/repository/commits/?ref_name=master" | grep x-total-pages | cut -d':' -f2 )
for ((i=1;i<=TOTAL_PAGES;i++)); do
SUM=$(($SUM + $(curl -Ss -k --request GET --header "PRIVATE-TOKEN: <my_private_token>" "http://<my_locally_hosted_web_server>/api/v4/projects/2/repository/commits/?ref_name=master&per_page=100&page=$i" | jq -r '. | length')));
done;
echo $SUM
答案 1 :(得分:1)
您可以简单地使用标题信息“ X-Total”:
commits_count=$(curl -Ss -k --head --header "PRIVATE-TOKEN: <my_private_token>" "http://<my_locally_hosted_web_server>/api/v4/projects/:id/merge_requests/:merge_request_iid/commits?per_page=5" | grep -m 1 X-Total | cut -d':' -f2 )