Skip to content

BUG: gh pr list and issue list --label uses OR logic instead of AND logic #419

@dterhorst-zz

Description

@dterhorst-zz

Describe the bug

  1. gh pr list --label appears to be using OR logic instead of AND logic
  2. gh pr list --label sometimes contains duplicates.

To show why this is a problem, imagine your PRs have the following labels:

  • in progress, ready for review, and reviewed
  • team a, team b, and team c.

Now let's say you want to find all of the PRs that are ready for review from team b.

So it makes sense that you try to search for --label "ready for review,team b". However, instead of getting a list of every PR that is both "ready for review" and "team b," you get:

  • Every PR labeled "ready for review," even if it is not from "team b."
  • Every PR labeled "team b," even if it is not "ready for review."

These results are useless from the perspective of someone who wants to review PRs from team b that are ready for review.

$ gh --version
gh version 0.5.4 (2020-02-04)
https://github.com/cli/cli/releases/tag/v0.5.4

Steps to reproduce the behavior

  1. Create a PR named "Example A" with labels test-a and test-c
  2. Create a PR named "Example B" with labels test-b and test-c
  3. Run gh pr list -l test-a,test-c

Expected vs actual behavior

Expected:

Pull requests for ...

#17874  Example A  example-a

Actual:

Pull requests for ...

#17875  Example B  example-b
#17874  Example A  example-a
#17874  Example A  example-a

Broken expectations:

  • I expected "Example B" to not appear at all, because it does not have the test-a label and therefore doesn't satisfy the given query.
  • I expected "Example A" to appear only once, because there is no point in having duplicates in this list.

Possible solutions

At minimum, use AND by default.

Ideally, support full boolean logic:

gh pr list -l "team a AND (ready for review OR NOT in progress)"

Logs

$ gh pr list -l test-a

Pull requests for ...

#17874  Example A  example-a
$ gh pr list -l test-b

Pull requests for ...

#17875  Example B  example-b
$ gh pr list -l test-c

Pull requests for ...

#17875  Example B  example-b
#17874  Example A  example-a
$ gh pr list -l test-a,test-c

Pull requests for ...

#17875  Example B  example-b
#17874  Example A  example-a
#17874  Example A  example-a

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp2Affects more than a few users but doesn't prevent core functions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions