git 如何过滤特定目标分支的所有 GitHub 拉取请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20547198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I filter all GitHub pull requests for a specific target branch
提问by AVIDeveloper
I'm working on a GitHub repo with lots of branches and pull requests.
我正在处理一个包含大量分支和拉取请求的 GitHub 存储库。
Let's say, for example, that I have the following pull requests:
例如,假设我有以下拉取请求:
a
to branchX
b
to branchX
c
to branchY
d
to branchX
e
to branchY
.
a
分支X
b
分支X
c
分支Y
d
分支X
e
到分支Y
。
Is there a way to find all the pull requests that are targeted for branch X
(i.e. a -> X
, b -> X
, d -> X
)?
有没有办法找到有针对性的分支的所有引入请求X
(即a -> X
,b -> X
,d -> X
)?
回答by Andor Dávid
Yes, you can do it.
是的,你可以做到。
In Github's terminology the "to branch" is "base"
So the search phrase is: is:open is:pr base:X
在 Github 的术语中,“to branch”是“base”所以搜索短语是: is:open is:pr base:X
Official description: Search based on branch names
官方说明:根据分支名称搜索
Optionally you can add is:merged
or is:unmerged
filters as well.
您也可以选择添加is:merged
或is:unmerged
过滤。
回答by AVIDeveloper
As of 2016-01-10 this has been added to the gh search bar api, see next answer.
截至 2016 年 1 月 10 日,这已添加到 gh 搜索栏 api,请参阅下一个答案。
Original accepted (and now outed answer) left un-edited.
原始接受(现在已发布的答案)未编辑。
Currently Not Available via Web Interface
目前无法通过 Web 界面使用
GitHub currently does not provide a way to filter pull-requests by their target branch through their web interface. Instead, all you currently get is just the entire list of pull-requests with the names of the topic branches:
GitHub 目前不提供通过其 Web 界面按目标分支过滤拉取请求的方法。相反,您当前获得的只是带有主题分支名称的整个拉取请求列表:
Clicking into a pull-request will show the target branch, but that doesn't really help you do any of the filtering that you want to do.
单击拉取请求将显示目标分支,但这并不能真正帮助您执行任何您想做的过滤。
You Can Use the GitHub REST API Instead
您可以改用 GitHub REST API
It is possible to filter pull-requests by using the GitHub REST API, however:
可以使用GitHub REST API过滤拉取请求,但是:
GET /repos/:owner/:repo/pulls?base=:branch
That should show you all the open pull-requests for the repo :owner/:repo
,
filtered by requests that target :branch
as their base branch. From the
documentation:
这应该会向您显示 repo 的所有打开的拉取:owner/:repo
请求,:branch
并按目标为它们的基本分支的请求进行过滤。从文档:
Filter pulls by base branch name. Example:
gh-pages
.
按基本分支名称过滤拉取。例子:
gh-pages
。
Example Using cURL
使用 cURL 的示例
If you have curl
available, you can test this on a public repo from the
command line:
如果curl
可用,您可以从命令行在公共存储库上测试它:
curl https://api.github.com/repos/codecombat/codecombat/pulls?base=master > \
pulls.json
That will return a JSON response of the following form:
这将返回以下形式的 JSON 响应:
[
{
"url": "https://api.github.com/repos/codecombat/codecombat/pulls/879",
"id": 14955421,
"html_url": "https://github.com/codecombat/codecombat/pull/879",
"head": {
"label": "DanielRodriguezRivero:patch-4",
"ref": "patch-4",
"sha": "baff84f0aeee12f23e3608558ae5341a0b5f939b",
"repo": {
"id": 16202384,
"name": "codecombat",
"full_name": "DanielRodriguezRivero/codecombat"
}
},
"base": {
"label": "codecombat:master",
"ref": "master",
"sha": "5e2f3ac7cb731a6e40e81737a5122c7fe1b746d3",
"repo": {
"id": 15193430,
"name": "codecombat",
"full_name": "codecombat/codecombat"
}
}
}
]
Each object in the array is a pull-request, filtered by the base/target branch. The JSON actually contains much more information than this, I've just removed most of it to show the relevant parts for this question.
数组中的每个对象都是一个拉取请求,由基本/目标分支过滤。JSON 实际上包含比这更多的信息,我刚刚删除了大部分信息以显示此问题的相关部分。
Parsing the cURL Response
解析 cURL 响应
You could probably write a Python/Ruby/PHP/Whatever script to then parse out the html_url
property of each pull-request and list it on the command line. For example, here's a simple Ruby script that will parse the output of a JSON response saved from the curl
output:
您可能会编写一个 Python/Ruby/PHP/Whatever 脚本,然后解析html_url
每个拉取请求的属性并将其列在命令行上。例如,这是一个简单的 Ruby 脚本,它将解析从输出中保存的 JSON 响应的curl
输出:
require 'json'
json = JSON.parse(File.read('./pulls.json'))
pulls = json.map { |pull| { title: pull['title'], url: pull['html_url'] } }
pulls.each do |pull|
puts pull.values
puts
end
Which outputs the following:
输出以下内容:
$ ruby parser.rb
Update es-ES.coffee
https://github.com/codecombat/codecombat/pull/879
Fix deltas referring to last system saved
https://github.com/codecombat/codecombat/pull/874
Refactor getNameById and add naming to systems in deltas
https://github.com/codecombat/codecombat/pull/866
Traducido varios textos del fichero es-ES.coffe al espa├?ol de Espa├?a
https://github.com/codecombat/codecombat/pull/865
Anon name collide
https://github.com/codecombat/codecombat/pull/834