我可以使用逻辑运算符 OR 搜索 github 标签吗?

Can I search github labels with logical operator OR?

我正在尝试像这样过滤 github 上的所有问题:

label:bug OR label:enhancement

但显然那是行不通的。我找到了这个页面 https://help.github.com/articles/searching-issues/ 我认为它必须写在那里,但我不知道该怎么做。

难道真的是不能过滤两个标签的问题?我的意思是这将是一项非常基本的任务,不是吗?

好吧,如果有人能就此事给我提示,我将很高兴听到。

Github 不支持以这种方式搜索标签。搜索问题被认为是“AND”而不是“OR”。

这是一个用于尝试的存储库。

Example demonstrating github supports "AND" in search

My expectations

应该出现增强、功能或两者兼而有之的所有问题..

  1. 增强和功能

  2. 增强

  3. 特征

Actual result

只显示了两者都显示的。

  1. 增强和功能

因此它不支持 OR 运算符。

更新

围绕此问题的另一个乏味的 hack 可能是在标签前使用 -(减号)符号删除不需要的标签。看下面的例子

label:enhancement -label:bug -label:foo -label:bar

这将列出所有没有 foo、bar 和 bug 作为标签的项目。这会起作用,但如果标签太多,可能会变得乏味。

Filtering issues containing only the enhancements

截至 2021 年的更新

现在您可以使用 OR 运算进行搜索。请看@VonC

的回答

例如,我正在过滤包含两个标签的问题,例如 - https://api.github.com/search/issues?q=language:python+label:%22good%20first%20issue%22+label:%22help%20wanted%22+state:open&sort=created 这个问题很老,但我希望它能帮助任何可能陷入同样问题的人。

截至 2021 年 8 月,另见此处: and: https://github.blog/changelog/2021-08-02-search-issues-by-label-using-logical-or/


理想情况下,GitHub 搜索将支持用于嵌套和分组的括号,以及逻辑 ANDORNOT 运算符。我希望他们支持这样的事情:

is:open AND is:pr AND (review-requested:ElectricRCAircraftGuy OR 
assignee:ElectricRCAircraftGuy) AND NOT(review-requested:"team:ORGNAME/team-1") AND 
archived:false AND (author:my-teammate-1 OR author:my-teammate-2 OR 
author:my-teammate-3)

相反,他们的搜索更受限制,而且也相当复杂,因为它具有非常不同的行为,具体取决于您在 中键入搜索的位置。由于不支持上述搜索方式,让我们考虑这种更有限的搜索尝试:


我的搜索:

is:open is:pr review-requested:ElectricRCAircraftGuy archived:false 
author:my-teammate-1 author:my-teammate-2 author:my-teammate-3

我想要的行为是这样的:

is:open AND is:pr AND review-requested:ElectricRCAircraftGuy AND archived:false AND 
(author:my-teammate-1 OR author:my-teammate-2 OR author:my-teammate-3)

但是根据您在何处进行此搜索,您将得到两种截然不同的行为。如果我转到 https://github.com/ --> Pull requests(在顶部)并在此处以黄色突出显示的搜索栏中键入搜索:

...然后我得到这个搜索行为:

is:open AND is:pr AND review-requested:ElectricRCAircraftGuy AND archived:false AND author:my-teammate-3

请注意,除 最后一个字段外,所有 author 个字段 都已删除。您一次只能搜索一个给定的字段!这太有限了!就好像我做了这个搜索:

is:open is:pr review-requested:ElectricRCAircraftGuy archived:false 
author:my-teammate-3

但是,如果我使用下面突出显示的全局搜索栏,它几乎可以在 https://github.com/ 上的任何地方使用,然后将 我的搜索 复制并粘贴到此搜索中酒吧:

...然后我得到了这个搜索行为,这正是我在这种情况下想要的:

is:open AND is:pr AND review-requested:ElectricRCAircraftGuy AND archived:false AND 
(author:my-teammate-1 OR author:my-teammate-2 OR author:my-teammate-3)

这意味着在全局搜索栏中,每个搜索词在幕后都与 AND 连接,除非给定字段有多个倍数,然后每个搜索词都与 [=26= 连接] 引擎盖下,如上图所示。然而,在本地 Pull Request 搜索栏中,每个搜索词在幕后都与 AND 连接,如果给定字段有多个倍数,则删除所有倍数 除了最后一个one,保留。这就是我所说的“令人费解的”搜索行为,因为结果 1) 令人困惑,2) 不同,取决于您使用的搜索栏,以及 3) 限制:即使您对 GitHub 了如指掌,仍然搜索它无法获得您可能想要的搜索结果。如果不进行广泛的研究和反复试验,很难理解正在发生的事情,而这正是我必须做的。 :(

那么,如果您想查看 my-teammate-1 或 my-teammate-2 或 my-teammate-3 的所有“审核请求”列表,您有什么选择?嗯,你可以做一个单一的全局搜索并添加书签,就像这样:

is:open is:pr review-requested:ElectricRCAircraftGuy archived:false 
author:my-teammate-1 author:my-teammate-2 author:my-teammate-3

或者您可以将 3 个单独的 Pull Request 搜索添加为书签,如下所示:

  1. 开放的、未归档的 PR 请求我的审查并且 my-teammate-1
    is:open is:pr review-requested:ElectricRCAircraftGuy archived:false 
    author:my-teammate-1
    
  2. 开放的、未归档的 PR 请求我的审查并且 my-teammate-2
    is:open is:pr review-requested:ElectricRCAircraftGuy archived:false 
    author:my-teammate-2
    
  3. 开放的、未归档的 PR 请求我的审查并且 my-teammate-3
    is:open is:pr review-requested:ElectricRCAircraftGuy archived:false 
    author:my-teammate-3
    

Pull Request 搜索的显示结果以更好的格式显示,因此即使对 3 个 Pull Request 搜索进行搜索并为其添加书签比对同一事物进行单个全局搜索并为其添加书签更痛苦,它可能是您喜欢做的。

如果你想做一些更复杂的事情,比如得到这个行为:

is:open AND is:pr AND (review-requested:ElectricRCAircraftGuy OR 
assignee:ElectricRCAircraftGuy) AND NOT(review-requested:"team:ORGNAME/team-1") AND 
archived:false AND (author:my-teammate-1 OR author:my-teammate-2 OR 
author:my-teammate-3)

...抱歉,目前无法进行。您必须利用适合您的搜索栏行为创建多个子搜索,并在必要时使用 - 符号排除结果。但是,您可以请求 GitHub 通过打开问题 here (not affiliated with GitHub--just a place to track issues) and then sending them a message here 并向他们提供您的问题和此 Stack Overflow 答案的 link 来实现这种更高级的搜索行为。

GitHub 搜索快速参考作弊 sheet:

提醒:read here 快速 refresher/summary 了解使用 GitHub 全局搜索栏与 GitHub 拉取请求搜索栏时的预期结果。

默认 GITHUB 拉取请求 (PR) 搜索:

  1. 我创建的所有打开的 PR
    1. https://github.com --> 单击最顶部 的“拉取请求”。
    2. 直接link:https://github.com/pulls
  2. 分配给我的所有 公开 PR
    1. https://github.com --> “拉取请求” --> “已分配”。
    2. 直接link:https://github.com/pulls/assigned
  3. 所有在评论中提到我的公开 PR(来自@my-username):
    1. https://github.com --> “拉取请求” --> “提到”。
    2. 直接link:https://github.com/pulls/mentioned
  4. 所有要求我审核的公开 PR
    1. https://github.com --> “拉取请求” --> “审查请求”。
    2. 直接link:https://github.com/pulls/review-requested

自定义 GITHUB 拉取请求(PR)搜索:

  1. 所有 PRS 开放,作者:

    1. 使用拉取请求搜索栏:

      1. https://github.com --> 单击最顶部 的“拉取请求”。

      2. 直接link:https://github.com/pulls

      3. 现在使用 top-center/top-right 处的搜索栏。

      4. 请注意,此搜索栏一次仅限一位作者:

         is:open is:pr archived:false author:username-1
         is:open is:pr archived:false author:username-2 
         is:open is:pr archived:false author:username-3 
         is:open is:pr archived:false author:username-4
        
      5. 这是上面 4 次搜索中第一个搜索的示例 URL:https://github.com/pulls?q=is%3Aopen+is%3Apr+archived%3Afalse+author%3Ausername-1

    2. [BEST] 使用 GitHub 全局搜索栏(任何 GitHub 页):

  2. 其他人要求我发表评论:

    1. 使用拉取请求搜索栏:

    2. [BEST] 使用 GitHub 全局搜索栏(任何 GitHub 页):

另请参阅:

  1. 我在这里回答如何通过“到分支”、“从分支”和作者搜索 PR,包括 使用自定义 Chrome您可以在搜索栏中快速触发的搜索引擎: How can I filter all GitHub pull requests for a specific target branch.

参考文献:

  1. https://webapps.stackexchange.com/questions/57933/how-to-search-with-logic-operators-on-github/111246#111246
  2. 另请参阅我的简短回答:https://webapps.stackexchange.com/questions/57933/how-to-search-with-logic-operators-on-github/142071#142071
  3. Getting started with searching on GitHub
    1. About searching on GitHub
    2. Searching issues and pull requests
    3. Using search to filter issues and pull requests
    4. Understanding the search syntax
    5. Troubleshooting search queries - 这里他们提到了 ANDORNOT 运算符,但他们似乎并没有真正实现这些,所以这个页面必须过时了:(。
  4. https://github.com/isaacs/github/issues/660

从 2021 年 8 月开始,是的。

但是,它尚未传播到 GitHub 企业(2021 年 10 月)

参见:

Search issues by label using logical OR

You can now search issues by label using logical OR.

Simply use a comma to separate the labels.
For example:

label:"good first issue",bug 

will list all issues with a label good first issue or bug.

除了其他人说的:OR 搜索在 GitHub Enterprise (GHE) 3.3 版后可用。请参阅 https://docs.github.com/enterprise-server@3.3/admin/release-notes#issues-and-pull-requests-changes 处的发行说明。

我认为它用于 git 次提交。考虑以下示例(对于 python 3)

from urllib.parse import quote

os.system('curl '+ '-H "Accept: application/vnd.github.cloak-preview"' + ' -s https://api.github.com/search/commits?q='+ \
             quote('(KEYWORD1 OR KEYWORD2 OR KEYWORD3) repo:[PUT YOUR TARGET SEARCH REPOSITORY LINK HERE]')  ')