Can I search github labels with logical operator OR?
Asked Answered
K

7

136

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.

Koball answered 19/3, 2015 at 2:10 Comment(2)
Related: How to search with logic operators on GitHub?Jacquelinejacquelyn
Since Aug. 2021, yes: label:bug,enhancement. See my answer belowRondelet
C
85

UPDATE as of 2021

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


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

Coulson answered 19/3, 2015 at 3:44 Comment(3)
Seems like a nice add on to their search...Give them a feedback :-) they might add itCoulson
Here's an unofficial place to log github issues you'd like github to fix, with an issue open for this specific probem: github.com/isaacs/github/issues/660. To get github's attention, simply contact GitHub and reference this issue and this very Stack Overflow question, as well as this one.Paleoclimatology
This is outdated, see answer by @RondeletHypsometry
R
88

Since Aug. 2021, yes.

However, it has not yet been propagated to GitHub Enterprise (Oct. 2021)
It is also in GHE .3.3 (Dec 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.

Rondelet answered 2/8, 2021 at 12:41 Comment(13)
Finally! Here is an upvote for this awesome news but now no one will upvote my answer :(Coulson
This change/new feature does not seem to have propagated to GitHub Enterprise yet, which is the paid version of GitHub used internally by many companies, such as where I work.Paleoclimatology
@GabrielStaples Indeed. I suspect GHE will eventually follow. What version are you using?Rondelet
How do I check the version?Paleoclimatology
@GabrielStaples check if https://mcmap.net/q/120972/-as-a-user-how-can-i-determine-the-installed-version-of-github-enterprise/6309 can help.Rondelet
If you open the dropdown list of Labels, you can use OR chaining if you ⇧ + click/return on a label.Gauffer
@Gauffer Nice. Is it available on GitHub Enterprise?Rondelet
Good news, but still very limited. Still not possible to eg. search for current iteration OR label=something ...Perdition
@Perdition I agree, that are still ways to improve that search.Rondelet
This sux. They should have just made a proper OR search. You can't even do things like commenter:foo OR author:fooLarena
@Larena I agree, this is frustrating.Rondelet
The lable:a,b works for me, but label:a OR base:main still doesn't work.Regardful
@Regardful I agree/confirm. There is no explicit "OR" operator.Rondelet
C
85

UPDATE as of 2021

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


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

Coulson answered 19/3, 2015 at 3:44 Comment(3)
Seems like a nice add on to their search...Give them a feedback :-) they might add itCoulson
Here's an unofficial place to log github issues you'd like github to fix, with an issue open for this specific probem: github.com/isaacs/github/issues/660. To get github's attention, simply contact GitHub and reference this issue and this very Stack Overflow question, as well as this one.Paleoclimatology
This is outdated, see answer by @RondeletHypsometry
P
27

As of Aug. 2021, also see here: Can I search github labels with logical operator OR? 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: How can I filter all GitHub pull requests for a specific target branch.

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
Paleoclimatology answered 5/5, 2020 at 16:36 Comment(9)
This is not an answer. This is a wishlist blog post.Hypsometry
@JRomero, I disagree with your claim it's not a valid answer. I stated what the current behavior was, and how to get the desired behavior under certain circumstances. I explained the limitations and when it doesn't work. I also explained how to contact GitHub to make a feature request. As a result of my and other peoples' efforts, it appears they may have now implemented the solution (see the new links I just added to the top of my answer). I know my answer has been linked to in multiple places on GitHub in regards to this discussion, and may have helped contribute to the outcome.Paleoclimatology
I feel your pain. but yeah this post is not the answer.Cobaltic
not "convoluted" but plain buggy.Larena
This doesn't work anymore...Liddy
@YagoDórea, which parts specifically?Paleoclimatology
@GabrielStaples using OR on the main search bar. At least didn’t work when I tried…Liddy
Regarding point 5 in your references - that's related to code search specifically. You can use AND, OR, and NOT operators in GitHub's code search UI.Unformed
Unfortunately, it seems that even in the global search bar the OR operation won't be used for filters dealing with different properties (I'm looking for issues that are open OR closed but only for the next milestone)Experientialism
D
2

You can search issues and PRs like this:

AND:

  • text: wordA AND wordB
  • qualifier: label:A label:B

OR:

  • text: wordA OR wordB
  • qualifier: label:A,B

NOT:

  • text: wordA NOT wordB
  • qualifier: label:A -label:B
Datary answered 23/5, 2023 at 15:47 Comment(0)
C
1

I figured it for git commits. Consider the following example (for 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]')  ')
Cress answered 2/6, 2022 at 7:18 Comment(0)
I
0

In addition to what others 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.

Intrusive answered 1/4, 2022 at 15:30 Comment(0)
R
-2

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.

Randeerandel answered 6/12, 2018 at 13:25 Comment(3)
What do you mean? Your answer filters on one label. Doesn't really answer the question or am I missing something?Parolee
@SybillePeters edited the answer, thanks for notifying me.Randeerandel
Interesting. Are you sure that OR is applied. I looked through the list and the results I checked had both labels. I started a different query, 'cause it's easier to check: api.github.com/search/…Parolee

© 2022 - 2024 — McMap. All rights reserved.