Skip to content

Conversation

@babakks
Copy link
Member

@babakks babakks commented Sep 1, 2025

This PR updates gh to use advanced issue search, if available.

Here are a couple of notes regarding the changes:

  • The search package (in pkg/search) is a general-purpose/independent component that handles the search for a couple of other commands. That is why, it now supports is:blocked, is:blocking or even handles the combination of is:merged and is:unmerged in a query, although no other part of the code actually uses these. It's just to eliminate the extra knowledge about what other packages need.

  • For mock feature detectors, where a feature detector was need but it's not really important for the test case (like asserting something other than the query), a mock that reflects the current status of the advanced issue search is used (which is supported as opt-in). This is to keep the tests up-to-date with the state of github.com and reflect the fact that gh prefers advanced issue search if it's available on the host.

  • For test cases where the code path should not involve any feature detection (e.g. when a list operation should take place, rather than a search), a nil detector is passed.

  • Two markers added to the code to help us identify the places we need to change in the future:

    • // TODO advancedIssueSearchCleanup: actionable when GHES 3.17 goes out of support and we don't need to maintain compatibility with the old issue search backend.
    • // TODO advancedSearchFuture: actionable when the advanced search syntax is available on global search or Pull Requests tabs.

A/C verification

A. On github.com

1. gh search issues (REST API)

When I run these commands:

gh search issues --sort created --repo cli/cli --repo cli/go-gh hyperlink
gh search issues --sort created --repo cli/cli --match title,body,comments foo
gh search issues --sort created --repo cli/cli --visibility private,public foo
gh search issues --sort created --owner @me --owner cli

Then the result is not empty, the query contains OR-ed qualifiers, and the API request URL includes the advanced_search=true query parameter

All confirmed, just an example here. HTTP request (note the advanced_search=true):

/search/issues?advanced_search=true&page=1&per_page=30&q=hyperlink+%28repo%3Acli%2Fcli+OR+repo%3Acli%2Fgo-gh%29+type%3Aissue&sort=created

URL-decoded query:

hyperlink (repo:cli/cli OR repo:cli/go-gh) type:issue

When I run above commands with --web
Then I see the old search syntax (i.e. no OR-ed qualifiers) in the global search GUI

Confirmed:
gh-search-issue-web

2. gh search prs (REST API)

When I run these commands:

gh search prs --sort created --repo cli/cli --repo cli/go-gh hyperlink
gh search prs --sort created --repo cli/cli --match title,body,comments foo
gh search prs --sort created --repo cli/cli --visibility private,public foo
gh search prs --sort created --owner @me --owner cli

Then the result is not empty, the query contains OR-ed qualifiers, and the API request URL includes the advanced_search=true query parameter

All confirmed, just an example here. HTTP request (note the advanced_search=true):

/search/issues?advanced_search=true&page=1&per_page=30&q=hyperlink+%28repo%3Acli%2Fcli+OR+repo%3Acli%2Fgo-gh%29+type%3Apr&sort=created

URL-decoded query:

hyperlink (repo:cli/cli OR repo:cli/go-gh) type:pr

When I run above commands with --web
Then I see the old search syntax (i.e. no OR-ed qualifiers) in the global search GUI

Confirmed:
gh-search-prs-web

3. gh issue list (GraphQL)

Given I'm in the local clone of the cli/cli repo
When I run gh issue list --search gh --label bug (to enforce a search API call)
Then the result is the same as it would when using the latest gh release, and the type argument is set to ISSUE_ADVANCED

Confirmed (note the ISSUE_ADVANCED):

GraphQL variables: {"limit":30,"owner":"cli","query":"gh label:bug repo:cli/cli state:open type:issue","repo":"cli","type":"ISSUE_ADVANCED"}

The results are the same:

$ diff <(gh issue list --search gh --label bug) <(./bin/gh issue list --search gh --label bug)
$ echo $?
0

Given I'm in the local clone of the cli/cli repo
When I run gh issue list --search gh --label bug --web
Then the pre-populated query is the same as it would when using the latest gh release

Confirmed. On latest gh:
gh-issue-list-web-old

Current PR:
gh-issue-list-web-new

4. gh pr list (GraphQL)

Given I'm in the local clone of the cli/cli repo
When I run gh pr list --search gh --label external (to enforce a search API call)
Then the result is the same as it would when using the latest gh release, and the type argument is set to ISSUE_ADVANCED

Confirmed (note the ISSUE_ADVANCED):

GraphQL variables: {"limit":30,"q":"gh label:external repo:cli/cli state:open type:pr","type":"ISSUE_ADVANCED"}

The results are the same:

$ diff <(gh pr list --search gh --label external) <(./bin/gh pr list --search gh --label external)
$ echo $?
0

Given I'm in the local clone of the cli/cli repo
When I run gh pr list --search gh --label external --web
Then the pre-populated query is the same as it would when using the latest gh release

Confirmed. On latest gh:
gh-pr-list-web-old

Current PR:
gh-pr-list-web-new

B. On GHES 3.17

Asserting the GHES instance version:

GH_HOST="<HOST>" gh api /meta --jq '.installed_version' | cat
# 3.17.0

1. gh search issues (REST API)

When I run

GH_HOST="<HOST>" USER="<USER>" gh search issues --sort created --repo "$USER/repo-a" --repo "$USER/repo-b" foo

Then the result is the same as it would when using the latest gh release, the query does not contain OR-ed qualifiers, and the API request URL does not include the advanced_search=true query parameter

Confirmed. Both show the same output (although expected 2, not 2x2 hits!):

Showing 4 of 4 issues

REPO            ID  TITLE  LABELS  UPDATED           
babakks/repo-b  #1  foo            about 13 hours ago
babakks/repo-b  #1  foo            about 13 hours ago
babakks/repo-a  #1  foo            about 14 hours ago
babakks/repo-a  #1  foo            about 14 hours ago

Also, no advanced_search=true and no ORs in query in the HTTP request:

GET /api/v3/search/issues?page=1&per_page=30&q=foo+repo%3Ababakks%2Frepo-a+repo%3Ababakks%2Frepo-b+type%3Aissue&sort=created HTTP/1.1

When I run above commands with --web
Then I see the old search syntax (i.e. no OR-ed qualifiers) in the global search GUI

Confirmed; since the GUI does not show the query here's the browser's address bar:
ghes-search-issues-web

2. gh search prs (REST API)

When I run

GH_HOST="<HOST>" USER="<USER>" gh search prs --sort created --repo "$USER/repo-a" --repo "$USER/repo-b" foo

Then the result is the same as it would when using the latest gh release, the query does not contain OR-ed qualifiers, and the API request URL does not include the advanced_search=true query parameter

Confirmed. Both show the same output (this time really 2 hits!):

Showing 2 of 2 pull requests

REPO            ID  TITLE  LABELS  UPDATED           
babakks/repo-b  #2  foo            about 14 hours ago
babakks/repo-a  #2  foo            about 14 hours ago

Also, no advanced_search=true and no ORs in query in the HTTP request:

GET /api/v3/search/issues?page=1&per_page=30&q=foo+repo%3Ababakks%2Frepo-a+repo%3Ababakks%2Frepo-b+type%3Apr&sort=created HTTP/1.1

When I run above commands with --web
Then I see the old search syntax (i.e. no OR-ed qualifiers) in the global search GUI

Confirmed; since the GUI does not show the query here's the browser's address bar:
ghes-search-prs-web

3. gh issue list (GraphQL)

Given I'm in the local clone of one the repos
When I run gh issue list --search foo (to enforce a search API call)
Then the result is the same as it would when using the latest gh release, and the type argument is set to ISSUE

Confirmed the outputs are the same (although it should be only one hit, not two!):

Showing 2 of 2 issues in babakks/repo-a that match your search

ID  TITLE  LABELS  UPDATED           
#1  foo            about 14 hours ago
#1  foo            about 14 hours ago

Also type is ISSUE:

GraphQL variables: {"limit":30,"owner":"babakks","query":"foo repo:babakks/repo-a state:open type:issue","repo":"repo-a","type":"ISSUE"}

Given I'm in the local clone of one the repos
When I run gh issue list --search foo --web
Then the pre-populated query is the same as it would when using the latest gh release

Confirmed. On latest gh:
ghes-issue-list-web-old

Current PR:
ghes-issue-list-web-new

4. gh pr list (GraphQL)

Given I'm in the local clone of one the repos
When I run gh pr list --search foo (to enforce a search API call)
Then the result is the same as it would when using the latest gh release, and the type argument is set to ISSUE

Confirmed the outputs are the same:

Showing 1 of 1 pull request in babakks/repo-a that matches your search

ID  TITLE  BRANCH      CREATED AT        
#2  foo    new-branch  about 14 hours ago

Also type is ISSUE:

GraphQL variables: {"limit":30,"q":"foo repo:babakks/repo-a state:open type:pr","type":"ISSUE"}

Given I'm in the local clone of one the repos
When I run gh pr list --search foo --web
Then the pre-populated query is the same as it would when using the latest gh release

Confirmed. On latest gh:
ghes-pr-list-web-old

Current PR:
ghes-pr-list-web-new

babakks added 20 commits August 30, 2025 15:51
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
…eSearchString` methods

Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
… syntax

Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
@babakks babakks marked this pull request as ready for review September 1, 2025 13:03
Copilot AI review requested due to automatic review settings September 1, 2025 13:03
@babakks babakks requested a review from a team as a code owner September 1, 2025 13:03
@babakks babakks requested a review from BagToad September 1, 2025 13:03
@babakks babakks requested review from Copilot September 2, 2025 10:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the GitHub CLI to use advanced issue search functionality when available, with backward compatibility for GHES 3.17 and older versions. The changes include enhanced search query formatting with OR operators, feature detection for advanced search capabilities, and comprehensive test updates.

Key changes:

  • Added feature detection for advanced issue search with different support levels (unsupported, opt-in, only backend)
  • Enhanced query formatting to support advanced syntax with OR operators for special qualifiers
  • Updated all search-related commands to use the new searcher interface with feature detection

Reviewed Changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/search/searcher.go Added feature detection and conditional query formatting for advanced issue search
pkg/search/query.go Implemented advanced issue search string formatting with OR grouping for special qualifiers
pkg/search/searcher_test.go Updated tests to include detector parameter and added advanced syntax test cases
internal/featuredetection/feature_detection.go Added SearchFeatures detection with version checking and GraphQL schema introspection
pkg/cmd/pr/list/http.go Updated search functions to use feature detection for proper search type selection
pkg/cmd/issue/list/http.go Updated issue search to conditionally use advanced syntax based on feature detection
Comments suppressed due to low confidence (1)

pkg/search/query.go:1

  • The advanced search logic handles grouping of special qualifiers like 'is:blocked' and 'is:blocking', but there's no documentation explaining why these specific values are grouped together. Consider adding a comment explaining the semantic relationship between these paired qualifiers.
package search

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

…ssue search

Signed-off-by: Babak K. Shandiz <babakks@github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Member

@BagToad BagToad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still working through it, but some ideas for the help docs you might be interested in.

Copy link
Member

@BagToad BagToad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; I left some comments. I think some of these things could be improved like removing the extra feature detector variable, if we'd like to do it in this PR, but that and all my other comments are minor and not blocking. I think it's clear that this PR as-is resolves the problems we needed to fix and does good job explaining what those problems are as well 👍

I particularly thought the query formatter you setup was a neat way of solving the problem. And I admire the attention to detail in the tests :)

Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
…esTab` field

Signed-off-by: Babak K. Shandiz <babakks@github.com>
@babakks babakks requested a review from BagToad September 8, 2025 17:54
Copy link
Member

@BagToad BagToad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback round! LGTM!

@babakks babakks merged commit 6b19a85 into trunk Sep 8, 2025
11 checks passed
@babakks babakks deleted the babakks/use-advanced-issue-search branch September 8, 2025 19:32
@Sashasissy

This comment was marked as spam.

@Sashasissy

This comment was marked as spam.

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Sep 12, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.78.0` -> `v2.79.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>cli/cli (cli/cli)</summary>

### [`v2.79.0`](https://github.com/cli/cli/releases/tag/v2.79.0): GitHub CLI 2.79.0

[Compare Source](cli/cli@v2.78.0...v2.79.0)

#### Advanced Issue Search Support

The GitHub CLI now supports advanced issue search syntax using:

- Searching issues: `gh search issues <advanced issue search query>`
- Searching pull requests: `gh search prs <advanced issue search query>`
- While listing issues: `gh issue list --search <advanced issue search query>`
- While listing pull requests: `gh pr list --search <advanced issue search query>`

For more information about advanced issue search syntax, see: "[Filtering and Searching Issues and Merge Requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/filtering-and-searching-issues-and-pull-requests#building-advanced-filters-for-issues)"

#### Copy OAuth Code Automatically

The GitHub CLI now supports writing the OAuth one-time pass code to the clipboard automatically during authentication:

- While logging in: `gh auth login --clipboard` / `gh auth login -c`
- While refreshing the token: `gh auth refresh --clipboard` / `gh auth refresh -c`

#### What's Changed

##### ✨ Features

- feat: `gh auth` Automatically copy one-time OAuth code to clipboard by [@&#8203;ankddev](https://github.com/ankddev) in [#&#8203;11518](cli/cli#11518)
- feat: add support for `--ref` in `gh cache delete` by [@&#8203;luxass](https://github.com/luxass) in [#&#8203;11592](cli/cli#11592)
- Use advanced issue search by [@&#8203;babakks](https://github.com/babakks) in [#&#8203;11638](cli/cli#11638)

##### 📚 Docs & Chores

- docs(release create): difference `--generate-notes` and `--notes-from-tag` by [@&#8203;ankddev](https://github.com/ankddev) in [#&#8203;11534](cli/cli#11534)
- refactor tests: use `slices.Equal` to simplify code by [@&#8203;minxinyi](https://github.com/minxinyi) in [#&#8203;11364](cli/cli#11364)
- Remove mention of public preview in trustedroot.go by [@&#8203;jkylekelly](https://github.com/jkylekelly) in [#&#8203;11652](cli/cli#11652)

##### :dependabot: Dependencies

- Bump sigstore/rekor to v1.4.1 by [@&#8203;BagToad](https://github.com/BagToad) in [#&#8203;11654](cli/cli#11654)
- chore(deps): bump actions/stale from 9 to 10 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;11663](cli/cli#11663)
- chore(deps): bump actions/setup-go from 5 to 6 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;11662](cli/cli#11662)

#### New Contributors

- [@&#8203;minxinyi](https://github.com/minxinyi) made their first contribution in [#&#8203;11364](cli/cli#11364)
- [@&#8203;jkylekelly](https://github.com/jkylekelly) made their first contribution in [#&#8203;11652](cli/cli#11652)
- [@&#8203;luxass](https://github.com/luxass) made their first contribution in [#&#8203;11592](cli/cli#11592)

**Full Changelog**: <cli/cli@v2.78.0...v2.79.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS45OC4xIiwidXBkYXRlZEluVmVyIjoiNDEuOTguMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
@FrankGDak47

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants