Ken*_*ahl 5 ruby github github-api pull-request
是否有可能获得与发布标记相关的拉取请求(或仅仅是数字)的列表?
我一整天都在查看Github API文档并尝试了不同的东西,但我看不出我是如何做到这一点的.
当我通过API获取提交时,我看不到拉取请求信息是可用的,即使拉取请求ID和链接在这里可用,例如:https: //github.com/octokit/octokit.rb/commit/1d82792d7d16457206418850a3ed0a0230defc81(参见左上角"master"旁边的#962链接)
您可以提取标签与前一个标签之间的提交,并SHA使用搜索 API 对每个提交搜索问题(拉取请求类型):
SHA。在这种情况下,您可以执行查询(*),将所有提交 sha 连接SHA:<commit sha>到查询(*)请注意,搜索查询限制为 256 个字符,因此您必须拆分这些搜索 API 调用
#!/bin/bash
current_tag="v4.8.0"
name_with_owner="octokit/octokit.rb"
access_token="YOUR_ACCESS_TOKEN"
tags=$(curl -s -H "Authorization: Token $access_token" \
"https://api.github.com/repos/$name_with_owner/tags")
key=$(jq -r --arg current_tag $current_tag 'to_entries | .[] | select(.value.name == $current_tag) | .key' <<< "$tags")
previous_tag=$(jq -r --arg index $((key+1)) '.[$index | tonumber].name' <<< "$tags")
echo "compare between $previous_tag & $current_tag"
commits=$(curl -s -H "Authorization: Token $access_token" \
"https://api.github.com/repos/$name_with_owner/compare/$previous_tag...$current_tag" | \
jq -r '.commits[].sha')
# you can have a query of maximum of 256 character so we only process 17 sha for each request
count=0
max_per_request=17
while read sha; do
if [ $count == 0 ]; then
query="repo:$name_with_owner%20type:pr"
fi
query="$query%20SHA:%20${sha:0:7}"
count=$((count+1))
if ! (($count % $max_per_request)); then
echo "https://api.github.com/search/issues?q=$query"
curl -s -H "Authorization: Token $access_token" \
"https://api.github.com/search/issues?q=$query" | jq -r '.items[].html_url'
count=0
fi
done <<< "$commits"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
651 次 |
| 最近记录: |