如何过滤特定目标分支的所有GitHub拉取请求

时间:2013-12-12 15:14:48

标签: git github pull-request

我正在开发一个包含大量分支和拉取请求的GitHub仓库。

比方说,我有以下拉取请求:

  • a分行X
  • b分行X
  • c分行Y
  • d分行X
  • e分行Y

有没有办法找到针对分支X的所有拉取请求(即a -> Xb -> Xd -> X)?

4 个答案:

答案 0 :(得分:37)

是的,你可以做到。

在Github的术语中,分支"分支"是"基地" 所以搜索短语是:is:open is:pr base:X

官方说明:Search based on branch names

您也可以选择添加is:mergedis:unmerged过滤器。

答案 1 :(得分:11)

截至2016-01-10,这已被添加到gh搜索栏api中,请参阅下一个答案。

原始接受(现在已解决的答案)未经编辑。


目前无法通过Web界面

GitHub目前没有提供过滤目标拉取请求的方法 通过他们的网络界面分支。相反,你现在得到的只是 带有主题分支名称的完整拉取请求列表:

GitHub Pull-Request UI

单击拉取请求将显示目标分支,但事实并非如此 真的可以帮助你做任何你想要做的过滤。

您可以使用GitHub REST API

可以使用GitHub REST API过滤提取请求, 但是:

GET /repos/:owner/:repo/pulls?base=:branch

那应该显示回购:owner/:repo的所有开放拉动请求, 通过将:branch作为基本分支的请求进行过滤。来自 文档:

  

按基本分支名称过滤。示例:gh-pages

使用cURL的示例

如果您有curl可用,则可以在公共仓库中对此进行测试 命令行:

curl https://api.github.com/repos/codecombat/codecombat/pulls?base=master > \
pulls.json

这将返回以下形式的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"
      }
    }
  }
]

数组中的每个对象都是一个pull-request,由base / target分支过滤。 JSON实际上包含更多内容 信息比这个,我刚刚删除了大部分信息来显示相关部分 对于这个问题。

解析cURL响应

您可以编写Python / Ruby / PHP / Whatever脚本,然后解析每个pull-request的html_url属性,并在命令行中列出它。例如,这是一个简单的Ruby脚本,它将解析从curl输出中保存的JSON响应的输出:

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

其中输出以下内容:

$ 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

答案 2 :(得分:1)

如何通过“from (head) branch”、“to (base) branch”和作者搜索 PR,包括使用自定义来执行此操作您可以在搜索栏中快速触发的 Chrome 搜索引擎:

注意:以下在 GitHub 上搜索 PR(拉请求)的目的是在此处的 PR 搜索栏中完成(https://github.com --> 顶部的“拉请求”)(直接链接: https://github.com/pulls),不会出现在几乎所有 GitHub 页面左上角的通用 GitHub 搜索栏中,尽管它们也可能在那里工作。

另见我的回答:Can I search github labels with logical operator OR?

在 GitHub 行话中,您要合并的分支是 head 分支,您要合并的分支是 base 分支。请参阅此处:https://docs.github.com/en/github/searching-for-information-on-github/searching-issues-and-pull-requests#search-by-branch-name。我不确定他们为什么不选择 from_branchto_branch,因为那样会更容易记住。

1.使用 my_branch 查找来自 head:my_branch 的所有 PR:

is:open is:pr archived:false head:my_branch

也可以指定一个存储库:

is:open is:pr archived:false repo:some_username/some_repository head:my_branch

2.找到所有合并到 my_branchbase:my_branch 的 PR:

is:open is:pr archived:false base:my_branch

也可以指定一个存储库:

is:open is:pr archived:false repo:some_username/some_repository base:my_branch

3.参考文献:

  1. 来自官方 GitHub 文档:https://docs.github.com/en/github/searching-for-information-on-github/searching-issues-and-pull-requests#search-by-branch-name

    <块引用>

    按分行名称搜索

    您可以根据请求来自的分支(“head”分支)或合并到的分支(“base”分支)过滤拉取请求。

    Qualifier               Example  
    ---------------------   -------------------------------------------------
    `head:HEAD_BRANCH`      `head:change is:closed is:unmerged` matches pull 
                            requests opened from branch names beginning with 
                            the word "change" that are closed.
    
    `base:BASE_BRANCH`      `base:gh-pages` matches pull requests that are 
                            being merged into the gh-pages branch.
    
  2. @Andor Dávid's answer here

4.更进一步:为 GitHub 搜索添加自定义 Google Chrome 搜索引擎

对于那些不知道的人,Chrome 浏览器允许您创建自定义搜索引擎。如果我转到浏览器搜索栏并输入 gto 后跟 SpaceTab,然后输入我的分支名称 my_branch,我会看到这。我实际上是在使用由我设置的 my_branch 快捷方式触发的自定义搜索引擎搜索合并到分支 gto 的所有开放 PR:

enter image description here

以下是配置这些的方法:

在 Chrome 中,单击右上角的 3 个点 --> 设置 --> 搜索引擎(在左窗格中)-->“管理搜索引擎”--> 在“其他搜索引擎”下,单击“添加“ 按钮。像这样设置: enter image description here

完成后点击“保存”。以下是我最喜欢的 3 个:

  1. 搜索合并到给定分支的 GitHub PR
    1. 搜索引擎:GitHub PRs merging TO branch
    2. 关键字:gto
    3. %s 代替查询的网址:https://github.com/pulls?q=is%3Aopen+is%3Apr+archived%3Afalse+base%3A%s
  2. 搜索从给定分支合并的 GitHub PR
    1. 搜索引擎:GitHub PRs merging FROM branch
    2. 关键字:gfrom
    3. %s 代替查询的网址:https://github.com/pulls?q=is%3Aopen+is%3Apr+archived%3Afalse+head%3A%s
  3. 搜索某个作者的 GitHub PR
    1. 搜索引擎:GitHub PRs BY this User
    2. 关键字:gby
    3. %s 代替查询的网址:https://github.com/pulls?q=is%3Aopen+is%3Apr+author%3A%s+archived%3Afalse+

确定要为 URL 搜索字符串添加什么内容的方法实际上非常简单:您只需转到 GitHub 并使用 GitHub 的工具手动进行搜索,然后复制并粘贴 URL,替换您想要的搜索字符串喜欢在自定义 Chrome 搜索引擎 URL 中使用 %s 进行搜索。而已!此过程适用于在您在其网站上进行自定义搜索后将其搜索变量存储到 URL 中的任何和所有网站,这些网站是许多(如果不是大多数)具有搜索功能的网站。

答案 3 :(得分:0)

既然 GitHub CLI 可用,下面是您对给定存储库执行此操作的方法。

您可以按照 appropriate instructions 为您的操作系统和首选软件包管理器安装 gh CLI。

我使用 cli/cli 存储库进行演示:

gh pr list --base trunk -R cli/cli

输出:

#3045  [hackday] mergeconflict                                                  hackday2102
#3044  Isolate test suite from environment variables                            env-tests
#3042  Remove functionality to add, view and edit binary files in gists         g14a:bug/gist-binary-files
#3023  Issue/pr create: exit with nonzero status code when "Cancel" was chosen  cancel-error-status
#3018  Add `pr create --body-file` flag                                         castaneai:pr-create-body-file
#3010  Add `api --cache` flag                                                   api-cache
#3008  Add interactive select in gist view                                      ganboonhong:interactive-gist-view
#2997  Feature/add files to gist                                                g14a:feature/add-files-to-gist
#2991  Repo create tweaks                                                       repo-create-prompt-change
#2953  Add `repo list` command                                                  cristiand391:add-repo-list
#2923  [WIP] first round of actions support                                     actions
#2728  Better completions                                                       rsteube:better-completions
#2261  pr status: show number of approvals                                      despreston:des/approval-count
#2160  Sign Windows .exes in a post-build hook                                  mbpreble:sign-windows-executables
#2080  store gh config in %APPDATA% on windows os                               RozzaysRed:appdata_configPath
相关问题