是否可以获取与发布代码相关的拉取请求列表(或只是数字)?
我一整天都在查看Github API文档,并尝试了不同的东西,但我无法看到我如何使这项工作。
当我通过API获取提交时,即使拉取请求ID&链接在这里可用,例如: https://github.com/octokit/octokit.rb/commit/1d82792d7d16457206418850a3ed0a0230defc81(请参阅左侧" master" 旁边的#962 链接)
答案 0 :(得分:1)
您可以提取标签与广告之间的提交。上一个和使用搜索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"
答案 1 :(得分:0)
我是用Ruby做的:
octokit
gem fix
或feat
代码如下所示:
require 'octokit'
Client = Octokit::Client.new(access_token: YOUR_GITHUB_TOKEN)
def getCommitsForTag(repo, tagName)
previousTag = getPreviousTag repo, tagName
(Client.compare repo, previousTag.name, tagName).commits
end
def getPreviousTag(repo, tagName)
tags = Client.tags repo
tags.each_with_index { |tag, index|
if tag.name == tagName
return tags[index+1]
end
}
end
def filterCommitsByPrefix(commits, commitPrefixArray)
filteredArray = []
commits.each { |commit|
commitPrefixArray.each { |commitPrefix|
if commit.commit.message.start_with?(commitPrefix)
filteredArray.push(commit)
end
}
}
filteredArray
end
def getPullRequestsByCommits(commits)
query = "SHA:"
commits.each { |commit|
query += "#{commit.sha},"
}
Client.search_issues query
end
def getPullRequestsForTag(repo, tag)
commitsForTag = getCommitsForTag repo, tag
fixCommits = filterCommitsByPrefix commitsForTag, ['fix']
featCommits = filterCommitsByPrefix commitsForTag, ['feat']
{
fixes: getPullRequestsByCommits(fixCommits).items,
features: getPullRequestsByCommits(featCommits).items
}
end
#Execute it like this:
pullRequestsForTag = getPullRequestsForTag 'octokit/octokit.rb', 'v4.8.0'
puts "Fix pull requests:"
puts pullRequestsForTag[:fixes]
puts "Feat pull requests:"
puts pullRequestsForTag[:features]