Commit graph

802 commits

Author SHA1 Message Date
Kynan Ware
db1dc976c2 test: use require.Equal instead of reflect.DeepEqual
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-11 16:03:33 -06:00
Kynan Ware
f7ff8f2079 fix: remove unused test helpers and fix gofmt
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-11 12:59:14 -06:00
Kynan Ware
1c274a8a56 fix(pr status): don't count cancelled checks as failures
When a GitHub Actions workflow uses concurrency with cancel-in-progress,
cancelled runs were counted as failures in `gh pr status` and
`gh pr view`, even when a newer run for the same check name succeeded.
The GitHub web UI and `gh pr checks` both handle this correctly.

Three changes fix this:

1. Add a `cancelled` check status category. Cancelled runs are now
   excluded from all summary counts (passing/failing/pending) and
   subtracted from the total, matching the web UI behavior.

2. Move `eliminateDuplicates` from pkg/cmd/pr/checks to
   `api.EliminateDuplicateChecks` (exported). The function operates
   entirely on `api.CheckContext` and is now shared by both `pr checks`
   and `ChecksStatus()` (used by `pr status` and `pr view`).

3. Apply deduplication in the `ChecksStatus()` slow path, keeping only
   the most recent run per check name — consistent with `pr checks`.

Fixes #12895

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-11 12:33:31 -06: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
Kynan Ware
38f9d7891b Fix linter and mock prompter signature 2026-01-26 13:29:22 -07:00
Kynan Ware
f6a09a3e5c Apply suggestions from code review
Co-authored-by: Babak K. Shandiz <babakks@github.com>
2026-01-26 13:29:22 -07:00
Kynan Ware
d04317c273 Add dynamic assignee search to PR edit flow
Introduces SuggestedAssignableActors API query and wires up a dynamic assignee search function in the PR edit command. Updates Editable and EditPrompter interfaces to support search-based multi-select for assignees, improving the user experience when assigning users to pull requests.
2026-01-26 13:29:22 -07:00
cuiweixie
b9c85fff68
typo: dont to don't 2026-01-26 22:25:00 +08:00
Andy Feller
1117477da2 Add test to ensure null values are skipped 2025-12-22 10:16:21 -05:00
Chris Henzie
4a106c1acf fix: prevent panic when processing null project items
The GraphQL API can return `null` nodes in the `projectItems`
connection, causing a runtime panic (nil pointer dereference) when the
CLI attempted to access fields on these nil nodes. This crash occurs
even with personal access tokens with full read access.

Adds a check to safely skip `nil` nodes in `ProjectsV2ItemsForIssue` and
`ProjectsV2ItemsForPullRequest`.

Signed-off-by: Chris Henzie <chrishenzie@google.com>
2025-12-16 11:14:55 -08:00
Kynan Ware
273fccd908 Check user and teams nil state instead of length 2025-11-10 11:09:14 -07:00
Kynan Ware
e154601f7d Ensure empty arrays for reviewers in PR API calls
Updated AddPullRequestReviews and RemovePullRequestReviews to send empty arrays instead of null values for reviewers and team_reviewers when no users or teams are specified, as required by the API.
2025-11-07 14:00:28 -07:00