Skip to content

gh pr edit: Add support for Copilot as reviewer with search capability, performance and accessibility improvements#12567

Open
BagToad wants to merge 14 commits intotrunkfrom
kw/multi-select-with-search-and-ccr
Open

gh pr edit: Add support for Copilot as reviewer with search capability, performance and accessibility improvements#12567
BagToad wants to merge 14 commits intotrunkfrom
kw/multi-select-with-search-and-ccr

Conversation

@BagToad
Copy link
Member

@BagToad BagToad commented Jan 28, 2026

Description

Adds Copilot Code Review (CCR) support and multiselect-with-search for reviewers in gh pr edit.

Key changes

API layer (api/queries_pr.go):

  • New RequestReviewsByLogin GraphQL mutation with userLogins, botLogins, teamSlugs (github.com only)
  • New SuggestedReviewerActors query combining suggestedReviewerActors, collaborators, and org teams
  • ReviewerCandidate interface with ReviewerUser, ReviewerBot, ReviewerTeam types
  • DisplayName()/DisplayNames() methods for user-friendly display (e.g., "Copilot (AI)")
  • Team slug extraction (org/slugslug) moved into REST functions

Query builder (api/query_builder.go):

  • Added ...on Bot{login} to prReviewRequests for Copilot support (silently ignored on GHES)

Edit command (pkg/cmd/pr/edit/edit.go):

  • reviewerSearchFunc for multiselect-with-search
  • Split updates: updatePullRequestReviewsGraphQL (github.com) vs updatePullRequestReviewsREST (GHES)
  • partitionReviewersByType to separate users, bots, teams
  • @copilot flag support for --add-reviewer/--remove-reviewer

Shared (pkg/cmd/pr/shared/):

  • EditableReviewers struct with separate Default (display) and DefaultLogins (API)
  • NewCopilotReviewerReplacer for @copilotcopilot-pull-request-reviewer

Notes for reviewers

  • GHES compatibility: Bot fragment silently ignored; falls back to REST for mutations
  • requestReviewsByLogin uses union: false (replace mode) to set the entire reviewer set
  • Copilot bot logins get [bot] suffix in API layer before mutation

@BagToad BagToad changed the title gh pr editAdd CCR and reviewer MultiSelectWithSearch gh pr edit: Add CCR and reviewer MultiSelectWithSearch Jan 28, 2026
@BagToad BagToad changed the title gh pr edit: Add CCR and reviewer MultiSelectWithSearch gh pr edit: Add support for Copilot as reviewer with search capability, performance and accessibility improvements Jan 28, 2026
Enables Copilot to be requested as a pull request reviewer, supporting both interactive and non-interactive flows. Introduces new reviewer search functionality, updates reviewer partitioning to distinguish users, bots, and teams, and adds a GraphQL mutation for reviewer management on github.com. Updates help text, tests, and internal APIs to support Copilot reviewer login and display names, while maintaining compatibility with GitHub Enterprise Server.
@BagToad BagToad force-pushed the kw/multi-select-with-search-and-ccr branch from 617a88d to 738b82d Compare January 28, 2026 06:11
@BagToad BagToad marked this pull request as ready for review January 28, 2026 16:27
@BagToad BagToad requested a review from a team as a code owner January 28, 2026 16:27
@BagToad BagToad requested review from babakks and Copilot January 28, 2026 16:27
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

Adds Copilot Code Review (CCR) support and a multi-select-with-search experience for editing PR reviewers via gh pr edit, including new API queries/mutations to support bots and improved reviewer display names.

Changes:

  • Introduces reviewer search plumbing in the edit flow and adds a github.com-specific GraphQL mutation path for setting reviewers (including Copilot bot).
  • Extends PR review-request GraphQL selection to include Bot and adds display-name helpers for reviewers (e.g., “Copilot (AI)”).
  • Adds @copilot reviewer replacement support and related unit tests.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
pkg/cmd/pr/shared/params_test.go Adds tests for @copilot reviewer replacement behavior.
pkg/cmd/pr/shared/params.go Splits Copilot replacement into assignee vs reviewer logins.
pkg/cmd/pr/shared/editable.go Introduces EditableReviewers, wires reviewer search prompting, and optimizes metadata fetching decisions.
pkg/cmd/pr/edit/edit_test.go Updates edit command tests for new reviewer flow/mutation behavior and GHES compatibility.
pkg/cmd/pr/edit/edit.go Wires reviewer search, partitions reviewers by type, and adds github.com GraphQL vs GHES REST reviewer update paths.
api/query_builder.go Adds ...on Bot{login} to PR review request selection for Copilot support.
api/queries_repo.go Introduces separate constants for Copilot assignee vs reviewer bot logins.
api/queries_pr.go Adds display helpers, REST team slug extraction, new reviewer mutation, and reviewer suggestion query/types.
Comments suppressed due to low confidence (1)

pkg/cmd/pr/edit/edit.go:582

  • partitionReviewersByType classifies bots only when the value equals api.CopilotReviewerLogin. If the search flow (or existing review requests) yields any other bot login, it will be treated as a user and sent to the wrong mutation input. Either broaden bot detection (e.g., by encoding type in the selection key or maintaining a map of login→type from search results) or ensure only Copilot bots can be selected.
// partitionReviewersByType splits reviewer identifiers into users, bots, and teams.
// Team identifiers are in the form "org/slug" and are returned as-is.
// Bot logins (currently only Copilot) are identified and returned separately.
func partitionReviewersByType(values []string) (users []string, bots []string, teams []string) {
	for _, v := range values {
		if v == "" {
			continue
		}
		if strings.ContainsRune(v, '/') {
			// Team: org/slug format, pass as-is
			teams = append(teams, v)
		} else if v == api.CopilotReviewerLogin {
			bots = append(bots, v)
		} else {
			users = append(users, v)
		}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Always send explicit lists for userLogins, botLogins, and teamSlugs
in RequestReviewsByLogin mutation, even when empty. Previously, empty
slices were omitted due to omitempty JSON behavior and len > 0 checks,
which prevented clearing all reviewers when using replace mode.

Empty slices are harmless no-ops in union mode, so we now send them
unconditionally for simpler logic.

Add test to verify the mutation receives empty slices when all
reviewers are removed.
Each source (suggestions, collaborators, teams) has base quota of 5.
Unfilled slots cascade to later sources, allowing up to 15 total.
Adds unit tests with HTTP mocks.
Fetch name field in reviewRequests GraphQL query and show as 'login (Name)'.
Query aliased fields without search filter to get stable counts.
Reword the comment for CopilotAssigneeLogin to indicate it refers to Copilot when retrieved as an assignee. This updates wording from the previous 'Actor/assignable actors' phrasing for clarity; no code behavior changed.
Remove a redundant struct-level comment and update the DefaultLogins field comment in pkg/cmd/pr/shared/editable.go to more accurately describe its purpose: used to disambiguate actors from display names rather than to compute add/remove sets.
Add clarifying comment in pkg/cmd/pr/edit/edit.go to note that missing assignee/reviewer search functions trigger a downstream fallback to legacy fetching. In pkg/cmd/pr/shared/editable.go remove a redundant line and add a TODO urging migration of non-interactive assignee updates to use the new logins input with ReplaceActorsForAssignable to avoid unnecessary fetching. These are comment and doc changes to clarify intent and future improvements.
Update comment in FetchOptions to specify that the APIs used for both GHES and GitHub.com accept user logins and team slugs directly, clarifying why non-interactive flows with Add/Remove don't need to fetch reviewers/teams. Comment-only change; no functional modifications.
Copy link
Member

@babakks babakks left a comment

Choose a reason for hiding this comment

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

LGTM!

Address PR review comments: code consistency and DRY improvements

- Add botTypeName const for consistency with teamTypeName
- Create extractTeamSlugs helper using strings.SplitN to simplify
  team slug extraction logic
- Replace duplicate code in AddPullRequestReviews and
  RemovePullRequestReviews with extractTeamSlugs helper
- Fix ClientMutationId naming with explicit graphql tag for
  consistency with other mutations in the codebase
@BagToad BagToad force-pushed the kw/multi-select-with-search-and-ccr branch from d7e41c1 to ebf932a Compare February 4, 2026 22:15
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.

3 participants