Commit graph

810 commits

Author SHA1 Message Date
William Martin
69d89a6590
Merge pull request #12884 from cli/babakks/use-min-discovery-fields-for-issue-create
fix(issue): avoid fetching unnecessary fields for discovery
2026-03-25 15:39:40 +01:00
Kynan Ware
1df6f84d70
Merge pull request #13009 from cli/fix/pr-create-assignee-metadata-13000
Use login-based assignee mutation on github.com
2026-03-24 20:29:11 -06:00
William Martin
c51769c977 Record agentic invocations in User-Agent header
Detect which AI coding agent is invoking gh by checking well-known
environment variables and include the agent name in the User-Agent
header sent to GitHub APIs.

Supported agents: Codex, Gemini CLI, Copilot CLI, OpenCode,
Claude Code, and Amp. Generic AI_AGENT env var is also supported
with validation to prevent header injection.

Fixes github/cli#1111

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-24 19:58:37 +01:00
Kynan Ware
11f177a8c3 feat(pr create, issue create): search-based assignee selection in MetadataSurvey
Wire up MultiSelectWithSearch for assignees in MetadataSurvey, replacing
the static MultiSelect that required bulk fetching all assignable actors.
This applies to both gh pr create and gh issue create interactive flows
when selecting assignees via the 'Add metadata' prompt.

Changes:
- Add assigneeSearchFunc parameter to MetadataSurvey
- Skip assignee bulk fetch when search func is available
- New SearchRepoAssignableActors API function for repo-level search
  (create flows have no issue/PR node ID yet)
- New RepoAssigneeSearchFunc in shared editable.go
- Refactor actorsToSearchResult helper shared by both search functions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-23 18:49:28 -06:00
Kynan Ware
33783748f3 review: address code review feedback
- Fix tests: assert logins (not display names) in actorLogins
- Remove dead ReplaceActorsForAssignableByID (no callers)
- Extract shared AssigneeSearchFunc to pkg/cmd/pr/shared/editable.go
- Remove duplicate assigneeSearchFunc from pr/edit and issue/edit

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-23 17:36:52 -06:00
Kynan Ware
e6d9019bc9 fix(pr create): use login-based assignee mutation on github.com
When ActorAssignees is true (github.com), pass assignee logins directly
to the ReplaceActorsForAssignable mutation instead of resolving logins
to node IDs. This eliminates the need to bulk fetch all assignable
users/actors and fixes a bug where providing assignees via CLI flag
and then interactively adding metadata would fail with 'not found'
because the cached MetadataResult had no assignee data.

Changes:
- Set state.ActorAssignees = true in pr create (was missing)
- AddMetadataToIssueParams: pass assigneeLogins when ActorAssignees
  is true, skip fetch and ID resolution entirely
- CreatePullRequest/IssueCreate: call ReplaceActorsForAssignableByLogin
  after creation to assign via logins
- Consolidate replaceActorsForAssignable mutation into api/ package
  (ReplaceActorsForAssignableByLogin + ReplaceActorsForAssignableByID)
- Remove duplicate replaceActorAssigneesForEditable from editable_http.go
- Add TODO replaceActorsByLoginCleanup markers on edit paths

Fixes cli/cli#13000

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-23 15:21:20 -06:00
William Martin
3921788f76
Revert "fix: clarify scope error while creating issues for projects" 2026-03-12 12:55:55 +01:00
William Martin
d45acae604
Revert "refactor: deduplicate scope error handling between api/client.go and project queries" 2026-03-12 12:45:48 +01:00
Babak K. Shandiz
27fb2da1c8
fix: improve docs around IssueRepoInfo
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-03-09 12:16:02 +00:00
Babak K. Shandiz
11e5be7842
test(api): add tests for GitHubRepo and IssueRepoInfo
Add success, not-found, and edge case tests for both GitHubRepo and
IssueRepoInfo, covering field population, parent repo handling,
viewer permission checks, and issues-disabled scenarios.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-09 11:30:46 +00:00
Babak K. Shandiz
5e2b2779d1
refactor(api): add IssueRepoInfo for minimal issue repo queries
Add a new IssueRepoInfo function that fetches only the fields needed
for issue creation (id, name, owner, hasIssuesEnabled, viewerPermission),
avoiding defaultBranchRef and other fields that require Contents:Read.

Also add StubIssueRepoInfoResponse helper to httpmock for testing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-09 11:30:02 +00:00
Kynan Ware
e047fa6b0e Address review comments: use actorDisplayName for Copilot author display
- Add actorDisplayName call in CommentAuthor.DisplayName for consistency
- Use require.Equal in TestActorDisplayName instead of manual comparisons
- Simplify user type name constant usage

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-06 20:36:46 -07:00
Kynan Ware
7198d270b4 Add generic actorDisplayName for all actor display names
Replace copilotDisplayName with actorDisplayName(typeName, login, name)
which handles all actor types: known bots get friendly names (e.g.
Copilot → 'Copilot (AI)'), regular bots return login, users with
names return 'login (Name)', others return login.

All DisplayName() methods on Author, CommentAuthor, GitHubUser,
AssignableUser, AssignableBot, RequestedReviewer, and ReviewerBot
now delegate to actorDisplayName with their available fields.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-06 11:55:09 -07:00
Kynan Ware
04bc0d27f4 Show friendly Copilot (AI) name in gh pr view
Add CopilotDisplayName helper that translates known Copilot bot
logins (copilot-pull-request-reviewer, copilot-swe-agent) to the
friendly 'Copilot (AI)' display name. Applied to:

- PullRequestReview.AuthorLogin() — review comment author
- Comment.AuthorLogin() — PR/issue comment author
- parseReviewers() in pr view — reviewer list display

This ensures gh pr view shows 'Copilot (AI)' instead of the raw
'copilot-pull-request-reviewer' login for both the reviewer status
line and any review comments left by Copilot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-06 11:19:43 -07:00
Kynan Ware
93c4340f29
Merge pull request #12627 from cli/kw/pr-create-multi-select-with-search-ccr
`gh pr create`: login-based reviewer requests and search-based interactive selection
2026-03-06 10:24:19 -07:00
Kynan Ware
7382b86c1a Fetch org teams via repository.owner inline fragment
Replace the top-level organization(login: $owner) query with
repository.owner { ... on Organization { teams } }. This uses
GraphQL inline fragments to conditionally fetch team data only
when the repo owner is an Organization, eliminating the need to
handle 'Could not resolve to an Organization' errors for
personal repos.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-06 09:47:47 -07:00
Kynan Ware
24fb7657cd Exclude PR author from reviewer candidates in SuggestedReviewerActors
Add author { login } to the SuggestedReviewerActors GraphQL query
and pre-seed the seen map with the author login so they are excluded
from all sources (suggestions, collaborators, teams). Previously the
author was only skipped via the isAuthor flag in the suggestions loop
but could still appear as a collaborator.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-05 15:53:50 -07:00
Kynan Ware
90bfa624c2 Exclude current user from suggested reviewers in gh pr create
Query the viewer login in SuggestedReviewerActorsForRepo and
pre-seed the seen map so the current user is filtered out of
collaborator results. You cannot review your own PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-05 15:36:48 -07:00
Kynan Ware
8f62e8116d Label Copilot detection in SuggestedReviewerActorsForRepo as a hack
Mark the piggyback-on-open-PR technique for detecting Copilot
reviewer availability as a HACK, since there is no repo-level API
to check Copilot eligibility without a PR context.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-05 10:56:47 -07:00
Kynan Ware
6341588f90 Add TODO requestReviewsByLoginCleanup in CreatePullRequest
Add a cleanup TODO comment above the GHES feature detection branch
in CreatePullRequest so we can track removing the ID-based reviewer
request path once GHES supports requestReviewsByLogin.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-05 10:56:31 -07:00
yuvrajangadsingh
fdd6388086 refactor: deduplicate scope error handling between api/client.go and project queries
Consolidate duplicated INSUFFICIENT_SCOPES error handling into a single
implementation. The project queries package now calls
api.GenerateScopeErrorForGQL instead of reimplementing the same logic.

Removes duplicated requiredScopesFromServerMessage, scopesRE, and the
associated test (already covered by api/client_test.go).

Fixes #12823
2026-03-05 20:57:32 +05:30
Kynan Ware
39874b7cf4
Merge pull request #12657 from yuvrajangadsingh/feature/pr-files-status
feat(pr): add changeType field to files JSON output
2026-03-03 16:04:00 -07:00
Kynan Ware
e725e38370
Merge pull request #12596 from elijahthis/fix/clarify-scope-error
fix: clarify scope error while creating issues for projects
2026-03-02 11:12:35 -07:00
yuvrajangadsingh
de61b2b65d feat(pr): add changeType field to files JSON output
Add the changeType field from the PullRequestChangedFile GraphQL type
to the PullRequestFile struct. This exposes the file status (added,
modified, deleted, renamed, copied, changed) in gh pr list --json files
and gh pr view --json files output.

Closes #11385
2026-03-01 15:35:05 +05:30
Simon Taranto
34c3b3c809 Add databaseId to assignees GraphQL fragment
The assignees query fragment only requested id, login, and name but the
GitHubUser struct includes a DatabaseID field. Since the field was never
requested from the API, it always defaulted to Go's zero value (0) in
JSON output. This adds databaseId to the fragment so the actual value is
returned.

Also adds ExportData test cases for assignees on both Issue and
PullRequest to verify databaseId round-trips correctly through JSON
serialization.
2026-02-25 10:26:46 -05:00
Kynan Ware
ceb904413d Clarify ReviewerCandidate relationship to AssignableActor
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-13 13:45:00 -07:00
Kynan Ware
72a6e9f3a7 Move PR review queries from queries_pr.go to queries_pr_review.go
Consolidate all review-related types, methods, and functions into
queries_pr_review.go for better code organization. The file is now
ordered by logical sections: review data types, review status, review
requests, reviewer candidates, API operations, and helpers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-13 13:40:59 -07:00
William Martin
166db75d36 pin REST API version to 2022-11-28
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-13 19:46:16 +01:00
Kynan Ware
1cb776384e Normalize /slug team shorthand to org/slug and fix docs 2026-02-11 14:33:13 -07:00
Kynan Ware
a8655bcda9 Include bot logins in login-based reviewer mutation guard 2026-02-11 13:55:57 -07:00
Kynan Ware
ad64d10bf4 Wire bot reviewer logins through CreatePullRequest 2026-02-11 13:16:23 -07:00
Kynan Ware
78aaa87718 Add toGitHubV4Strings helper to reduce code duplication 2026-02-05 14:01:21 -07:00
Kynan Ware
04bf86a72c Address PR review comments
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
2026-02-05 14:01:21 -07:00
Kynan Ware
c0febc1ac8 Add toGitHubV4Strings helper to reduce code duplication 2026-02-04 15:18:49 -07:00
Kynan Ware
ebf932a043 Address PR review comments
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
2026-02-04 15:15:29 -07:00
Kynan Ware
9904f7d1b9 gh pr create: CCR and multiselectwithsearch 2026-02-04 14:56:05 -07:00
elijahthis
71564fd4a1 test: TestGenerateScopeErrorForGQL and TestRequiredScopesFromServerMessage 2026-02-01 23:26:03 +01:00
elijahthis
6f739036b8 fix: clarify scope error while creating issues for projects 2026-02-01 23:12:01 +01:00
Kynan Ware
7303c44483 Clarify Copilot assignee comment
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.
2026-01-30 11:17:25 -07:00
Kynan Ware
c8b1409803 Use unfiltered totalCount for reviewer 'more results' display
Query aliased fields without search filter to get stable counts.
2026-01-29 12:54:04 -07:00
Kynan Ware
484526da77 Include name in reviewer display for existing review requests
Fetch name field in reviewRequests GraphQL query and show as 'login (Name)'.
2026-01-29 12:46:26 -07:00
Kynan Ware
2d191e5ba0 Implement cascading quota for reviewer suggestions
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.
2026-01-29 11:30:08 -07:00
Kynan Ware
d643d5386e fix(pr edit): send empty slices to clear reviewers in replace mode
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.
2026-01-29 10:37:11 -07:00
Kynan Ware
7f8ca2ca81 Fix return proper slug only for ReviewerTeam 2026-01-29 10:23:18 -07:00
Kynan Ware
738b82ddab Add CCR and reviewer MultiSelectWithSearch
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.
2026-01-27 23:11:51 -07:00
Kynan Ware
23e80a9d24 Remove outdated comment in SuggestedAssignableActors
Deleted a comment about the query variable being passed as null when empty, as it is no longer relevant or necessary.
2026-01-26 15:09:58 -07:00
Kynan Ware
28e07666f8 Return total assignee count in SuggestedAssignableActors
Updated SuggestedAssignableActors to return the total count of available assignees in the repository. Modified assigneeSearchFunc to use this count to calculate and display the number of additional assignees beyond the current results.
2026-01-26 14:33:45 -07:00
Kynan Ware
48bea46504 Remove unused Viewer struct from SuggestedAssignableActors
Deleted the Viewer struct from the responseData type in SuggestedAssignableActors as it was not being used.
2026-01-26 13:48:22 -07:00
Kynan Ware
dc105ce7a4 Simplify variables map in SuggestedAssignableActors
Refactored the construction of the variables map by directly assigning the 'query' key, removing the conditional logic for nil assignment.
2026-01-26 13:29:22 -07:00
Kynan Ware
346bd8c002 Simplify suggested assignable actors
Simplifies SuggestedAssignableActors by no longer including the viewer in the returned actors list when the query is blank. Removes related logic and variables for viewer handling.
2026-01-26 13:29:22 -07:00