Can I search github labels with logical operator OR?

GithubFilter

Github Problem Overview


I'm trying to filter all my issues on github like this:

label:bug OR label:enhancement

But obviously that does not work. I found this page https://help.github.com/articles/searching-issues/ and i thought it must be written there, but I cannot figure out how to do it.

Could it really be that one cannot filter issues of two labels? I mean that would be such a basic task, wouldn't it?

Well if anyone could give me a hint upon that matter I'd be glad to hear it.

Github Solutions


Solution 1 - Github

Github does not support searching the labels that way. The searching for issues is considered to be an "AND" instead of an "OR" .

Here's a repository used to try this out.

Example demonstrating github supports "AND" in search

> My expectations

All the issues that are enhancement, feature or both should appear..

  1. enhancement and feature

  2. enhancement

  3. feature

> Actual result

Only the ones which were both were shown.

  1. enhancement and feature

Hence it does not support OR operator.

UPDATE

Another tedious hack around this could be remove the unwanted labels using a -(minus) symbol before the label. Look at the following example

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

This will list all the items not having foo, bar and bug as a label on them. This will work but can become tedious if labels are too many.

Filtering issues containing only the enhancements

UPDATE as of 2021

Now you can search using an OR operation. Please see the answer by @VonC

Solution 2 - Github

Since Aug. 2021, yes.

However, it has not yet been propagated to GitHub Enterprise (Oct. 2021)

See:

> ## 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.

Solution 3 - Github

As of Aug. 2021, also see here: https://stackoverflow.com/questions/29136057/can-i-search-github-labels-with-logical-operator-or/68621781#68621781 and: https://github.blog/changelog/2021-08-02-search-issues-by-label-using-logical-or/.


Ideally, GitHub search would support parenthesis for nesting and grouping, and logical AND, OR, and NOT operators. What I would like is for them to support something like this:

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)

Instead, their search is much more limiting, and also pretty convoluted since it has VERY DIFFERENT behavior depending on where you type your search. Since the above search style is not supported, let's consider this more limited search attempt instead:


My search:

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

The behavior I WANT is this:

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)

But depending on where you do this search, you will get two very different behaviors. If I go to https://github.com/ --> Pull requests (at top) and type the search into this search bar highlighted in yellow here:

enter image description here

...then I get this search behavior:

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

Notice that all author fields except for the last one were DELETED. You can only search for ONE OF A GIVEN FIELD AT A TIME! This is sooo limiting! It is as though I had done this search:

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

However, if I use the global search bar, highlighted below, which is available pretty much anywhere on https://github.com/, and copy and paste My search into this search bar:

enter image description here

...then I get this search behavior, which is exactly what I want in this case:

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)

This means that in the global search bar, each search term is joined with AND under the hood, unless there are multiples of a given field, and then each of those is joined with OR under the hood, as shown above. In the local Pull Request search bar, however, each search term is joined with AND under the hood, and if there are multiples of a given field, all of the multiples are deleted except for the last one, which is retained. This is what I call "convoluted" search behavior, since the results are 1) confusing, 2) different, depending on which search bar you use, and 3) limiting: even if you knew everything about GitHub search it still impossible to obtain the search results you might want. It's very hard to understand what's happening without extensive research and trial and error, which is exactly what I had to do. :(

So, what are your options if you want to see a list of all "Review requests" by my-teammate-1 OR my-teammate-2 OR my-teammate-3? Well, you can do and bookmark a single global search, like this:

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

OR you can do and bookmark 3 separate Pull Request searches, like this:

  1. Open, non-archived PRs requesting my review AND by my-teammate-1
    is:open is:pr review-requested:ElectricRCAircraftGuy archived:false 
    author:my-teammate-1
    
  2. Open, non-archived PRs requesting my review AND by my-teammate-2
    is:open is:pr review-requested:ElectricRCAircraftGuy archived:false 
    author:my-teammate-2
    
  3. Open, non-archived PRs requesting my review AND by my-teammate-3
    is:open is:pr review-requested:ElectricRCAircraftGuy archived:false 
    author:my-teammate-3
    

The display results of the Pull Request searches are displayed in a nicer format, so even though doing and bookmarking the 3 Pull Request searches is more of a pain than doing and bookmarking a single global search of the same thing, it might be what you prefer to do.

And if you want to do something more complicated, such as get this behavior:

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)

...sorry, it's not currently possible. You'll have to create multiple sub-searches taking advantage of the search bar behavior that works for you, and using the - sign where necessary to exclude results. But, you can request that GitHub implement this more advanced search behavior by opening an issue here (not affiliated with GitHub--just a place to track issues) and then sending them a message here and giving them the links to your issue and to this Stack Overflow answer.

GitHub search quick-reference cheat sheet:

Reminder: read here for a quick refresher/summary of what to expect when using the GitHub global search bar versus the GitHub Pull Request search bar.

DEFAULT GITHUB PULL REQUEST (PR) SEARCHES:

  1. All open PRs created by me:
    1. https://github.com --> click "Pull requests" at the very top.
    2. Direct link: https://github.com/pulls
  2. All open PRs assigned to me:
    1. https://github.com --> "Pull requests" --> "Assigned".
    2. Direct link: https://github.com/pulls/assigned
  3. All open PRs which mention me in a comment (via @my-username):
    1. https://github.com --> "Pull requests" --> "Mentioned".
    2. Direct link: https://github.com/pulls/mentioned
  4. All open PRs for which my review is requested:
    1. https://github.com --> "Pull requests" --> "Review requests".
    2. Direct link: https://github.com/pulls/review-requested

CUSTOM GITHUB PULL REQUEST (PR) SEARCHES:

  1. ALL PRS OPEN, BY AUTHOR:

    1. Using the Pull request search bar:

      1. https://github.com --> click "Pull requests" at the very top.

      2. Direct link: https://github.com/pulls

      3. Now use the search bar at the top-center/top-right.

      4. Note that this search bar is limited to only one author at a time:

         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. Here is a sample URL for the first of the 4 searches just above: https://github.com/pulls?q=is%3Aopen+is%3Apr+archived%3Afalse+author%3Ausername-1

    2. [BEST] Using the GitHub global search bar (main search bar at top-left of any GitHub page):

  2. REVIEWS REQUESTED OF ME BY OTHERS:

    1. Using the Pull request search bar:

    2. [BEST] Using the GitHub global search bar (main search bar at top-left of any GitHub page):

See also:

  1. My answer here on how to search for PRs by "to branch", by "from branch", and by author, including doing this using custom Chrome search engines you can quickly trigger in your search bar: https://stackoverflow.com/questions/20547198/how-can-i-filter-all-github-pull-requests-for-a-specific-target-branch/66287268#66287268.

References:

  1. https://webapps.stackexchange.com/questions/57933/how-to-search-with-logic-operators-on-github/111246#111246
  2. See also my shorter answer here: 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 - here they mention AND, OR, and NOT operators, but they don't seem to actually have these implemented, so this page must be out-of-date :(.
  4. https://github.com/isaacs/github/issues/660

Solution 4 - Github

In addition to what other said: OR searches are available in GitHub Enterprise (GHE) since version 3.3. See the release notes at https://docs.github.com/[email protected]/admin/release-notes#issues-and-pull-requests-changes.

Solution 5 - Github

I am for example filtering issues containing two labels like - https://api.github.com/search/issues?q=language:python+label:%22good%20first%20issue%22+label:%22help%20wanted%22+state:open&sort=created The question is old but I hope it will help anyone who might be stuck on the same problem.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMercView Question on Stackoverflow
Solution 1 - Githubcafebabe1991View Answer on Stackoverflow
Solution 2 - GithubVonCView Answer on Stackoverflow
Solution 3 - GithubGabriel StaplesView Answer on Stackoverflow
Solution 4 - GithubimphilView Answer on Stackoverflow
Solution 5 - GithubMaxView Answer on Stackoverflow