Commit graph

140 commits

Author SHA1 Message Date
Ville Skyttä
d8b8655f21 Grammar fixes 2026-05-01 10:22:13 +03:00
Kynan Ware
3c00ffdade refactor(pr shared): consolidate ActorAssignees and ActorReviewers into ApiActorsSupported
The CLI had two per-entity flags (ActorAssignees on EditableAssignees and
IssueMetadataState, ActorReviewers on IssueMetadataState) threaded through
different layers of the stack to distinguish github.com from GHES. Both
flags were always set from the same source (issueFeatures.ActorIsAssignable)
and never had different values, but they were carried independently on
different structs. This led to a confusing asymmetry where:

- EditableAssignees had ActorAssignees but EditableReviewers had nothing
- The PR edit flow piggybacked on editable.Assignees.ActorAssignees to
  make reviewer mutation decisions, which was misleading
- RepoMetadataInput only had ActorAssignees with no reviewer equivalent

This commit replaces all per-entity flags with a single ApiActorsSupported
bool hoisted to the shared level on Editable, IssueMetadataState, and
RepoMetadataInput. Both assignees and reviewers now key off the same signal.

Every branch site is marked with // TODO ApiActorsSupported so we can grep
for cleanup sites when GHES eventually supports the actor-based mutations
(replaceActorsForAssignable, requestReviewsByLogin).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-24 21:04:41 -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
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
08c7a4c207 Replace @copilot with Copilot reviewer login in gh pr create
Wire CopilotReviewerReplacer into NewIssueState so that
`gh pr create --reviewer @copilot` correctly resolves to the
copilot-pull-request-reviewer bot login, matching the behavior
already implemented in gh pr edit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-05 15:15:33 -07:00
William Martin
7448aed8ab fork default branch only in pr create 2026-02-12 16:56:14 +01:00
Kynan Ware
1d730951d2 Use org/slug format in test fixtures and remove /slug normalization 2026-02-11 14:51:12 -07:00
Kynan Ware
1cb776384e Normalize /slug team shorthand to org/slug and fix docs 2026-02-11 14:33:13 -07:00
Kynan Ware
38661646ee Update test assertions to expect org/slug team format 2026-02-11 13:18:07 -07:00
Kynan Ware
9904f7d1b9 gh pr create: CCR and multiselectwithsearch 2026-02-04 14:56:05 -07:00
majiayu000
9daa22ebac fix: error when head and base refs are identical in pr create
When a user runs `gh pr create` with head and base refs pointing to
the same ref in the same repository, the command now exits with an
error instead of proceeding with an invalid PR creation.

This prevents accidental pushes to the main branch and provides clear
feedback when users attempt to create a PR from the base branch.

Cross-repository PRs (e.g., from forks) with the same branch name
continue to work as expected.

Fixes #11903

Signed-off-by: majiayu000 <1835304752@qq.com>
2025-12-26 19:14:06 +08:00
Andy Feller
bbc3d02cb3 Refactor tab completion test
This commit moves the `gh pr create` tab completion test closer to the logic rather than the commands that use it.

This should ensure that any command or flag that lists reviewers will present teams and users as expected.
2025-07-30 09:25:33 -04:00
Andy Feller
c9bc185209 Test gh pr create --reviewer tab completion 2025-07-30 09:16:44 -04:00
Andy Feller
8f20f0ab53 Include org teams for PR reviewers
This commit enhances the following scenarios to include organization teams as pull request reviewers:

1. Interactive `gh pr create` during additional metadata
2. Tab completing `gh pr create --reviewer`
3. Tab completing `gh pr edit --add-reviewer`
4. Tab completing `gh pr edit --remove-reviewer`

Additionally, a new `gh pr create` test case for ensuring that teams show up within interactive prompts has been added.
2025-07-29 18:19:22 -04:00
Kynan Ware
5a6cac3643 Add tests for reviewer team handling in PR creation
Added test cases to verify that teams are fetched when reviewers include teams and not fetched when only users are specified. This ensures correct behavior when requesting reviews from users and teams during pull request creation.
2025-07-23 10:15:30 -06:00
Kynan Ware
df317d4a05 FIX: conditionally fetching team reviewers
Updated the logic for fetching team reviewers in PR edit and create flows. In `pr edit`, team reviewers are always fetched for consistency with existing behavior, with a note to potentially align with `pr create` logic in the future. In `pr create`, team reviewers are now only fetched if a reviewer contains a slash, aligning with behavior before the regression.
2025-07-22 11:00:47 -06:00
Andy Feller
260519dc69
Merge pull request #11279 from cli/andyfeller/issue-create-assign-copilot
Assign Copilot during `gh issue create`
2025-07-16 17:01:32 -04:00
Andy Feller
1eeb797975
Revert "Fix: gh pr create prioritize --title and --body over --fill w…"
This reverts commit b31f38c946.
2025-07-14 17:23:09 -04:00
Andy Feller
fd1c31de59 Fix gh pr create tests from metadata change
These are the minimum fixes necessary to repair `gh pr create` tests after refactoring the underlying metadata resolution logic.
2025-07-11 15:32:17 -04:00
Daniel Krzeminski
b31f38c946
Fix: gh pr create prioritize --title and --body over --fill when --web is present (#10547)
* fix: prioritize title and body over autofill for prs

* fix: prioritize title and body over autofill tests

* refactor: collapse state conditions

---------

Co-authored-by: Babak K. Shandiz <babakks@github.com>
2025-06-24 12:54:43 +00:00
William Martin
1a5b7ca60c Feature detect v1 projects for preview URL
As far as I can see, when there is project metadata, the preview option
will never be shown in the interactive multiselect, so I don't believe
this change has any functional difference. However, I did use the
opportunity to drive out tests for generateCompareURL
2025-05-02 17:42:23 +02:00
William Martin
5a3aee056a Feature detect v1 projects on interactive pr create 2025-05-02 17:42:23 +02:00
William Martin
9822bb5d07 Feature detect v1 projects on web mode pr create 2025-05-02 15:11:04 +02:00
William Martin
e995a873cb Feature detect v1 projects on non-interactive pr create 2025-05-02 15:08:34 +02:00
William Martin
a9dbda6913 Rework ref usage when finding and creating PRs 2025-04-15 13:38:10 -06:00
Kynan Ware
bf7bf99f54 fix(pr create & stubs): handle exitcode in stubs 2025-04-15 13:38:10 -06:00
Kynan Ware
041f02c980 docs(pr create): standard <user>:<branch> syntax
Standardize <user>:<branch> syntax wherever it is described in comments.
2025-04-15 13:38:10 -06:00
Kynan Ware
bab7dc650b test(pr create): update repo owner names in tests 2025-04-15 13:38:10 -06:00
Kynan Ware
da235b134b tests(pr create): remove irrelevant comments 2025-04-15 13:38:10 -06:00
Kynan Ware
9b96e6cded doc(pr create): fix typo in test comments
Co-authored-by: Tyler McGoffin <jtmcg@github.com>
2025-04-15 13:38:10 -06:00
Kynan Ware
c0c5d9123d refactor(pr create): use GetPRHeadLabel()
Use PrRefs.GetPRHeadLabel() instead of headBranchLabel.
Also remove headBranchLabel from CreateContext struct.

To do this, we needed a new identifier for when the head repo should be
created via a new fork of the base repo. Previously, this was done by
checking if the head repo was nil, but if we want to call
GetPRHeadLabel(), it requires a non-nil head repo to construct the
headBranchLabel. So, instead of the head repo being nil to signal
a fork, we pass a new forkHeadRepo bool in the CreateContext struct.
This also makes the decision to fork more intentional; now the decision
is made clearly instead of if the headRepo happens to be nil.
2025-04-15 13:38:10 -06:00
Kynan Ware
178fb40515 refactor(pr create): Use PrRefs in CreateContext
Replace BaseRepo, HeadRepo, HeadBranch with PrRefs in CreateContext struct.
2025-04-15 13:38:10 -06:00
Kynan Ware
c3087cde99 refactor(pr create): Refactor NewCreateContext
- Use prRefs instead of local vars more.
- Rename variables for readability.
- Improve comments.
- Refactor tests.
2025-04-15 13:38:10 -06:00
Kynan Ware
dc486258cb test(pr create): test --head=<remote>:<branch> 2025-04-15 13:38:10 -06:00
Kynan Ware
a8d01c70cd feat: support @{push} revision syntax 2025-04-15 13:38:10 -06:00
Kynan Ware
c1fbc2f05b test(many): fix whitespace in tests expectations
Due to https://github.com/charmbracelet/glamour/pull/334, the margin
used for markdown rendering has changed by a couple spaces. This
corrects the relevant tests to accomodate that change.
2025-03-27 14:21:13 -06:00
David Livingston
5004ba2b91 update default upstream when forking repo
update default upstream when forking repo

remove unnecessary variable
2025-02-17 11:14:16 +08:00
Tyler McGoffin
de9971d718
Merge pull request #9208 from Frederick888/find-pr-by-rev-parse-push
Find PRs using `@{push}`
2025-01-29 12:11:32 -08:00
Tyler McGoffin
4382bdf072 Fix pr create tests
Due to the refactor of BranchConfig, the tests for `pr create` no longer
require a handful of stubbed git commands.

Additionally, I noticed some overlap between `pr create`'s existing logic
with the new finder code. I suspect that the finder's new ParsePRRefs
helper could be leveraged here as well, which would allow us to respect
non-centralized workflows pr create in the same way we are respecting them
in `gh pr view` and `gh pr status`
2025-01-24 14:01:44 -08:00
Otto Kekäläinen
b19e682455
Update test to be compatible with latest Glamour v0.8.0
Latest Glamour has slightly changed logic in line length / wrapping,
resulting test failures due to string mismatch. Update tests and bump
dependency to v0.8.0, and others to the bare minimal level as generated
by `go mod tidy`.

This was detected then building the GitHub cli package `gh` in Debian
started to fail with src:golang-github-charmbracelet-glamour 0.8.0-1.

Closes: #10179
2025-01-22 20:13:40 -08:00
Tyler McGoffin
48e2681017 Merge branch 'trunk' into find-pr-by-rev-parse-push
A recent refactor caused the API for ReadBranchConfig to change, resulting
in changes for its consumers. Additionally, there was a large refactor of
the tests associated with ReadBranchConfig and its consumers to gain
confidence in this refactor. This commit attempts to resolve the
conflicts between the refactor and this effort as well as massage the
changes introduced here to reflect the refactor.

The refactor PR can be found here: https://github.com/cli/cli/pull/10197

I'll note that there are still a few failing tests in status_test.go. I
haven't had a chance to fully grok while they are failing, yet, and
suspect that some insights from the original PR author may be helpful
here.

Full disclaimer: I haven't verified any of this is working locally yet.
My primary motivation is to get these new changes working together in a
manner that unblocks further iteration on this effort.

* trunk: (79 commits)
  Enhance help docs on ext upgrade notices
  chore: fix some function names in comment
  Expand docs on cleaning extension update dir
  Simplifying cleanExtensionUpdateDir logic
  Separate logic for checking updates
  Capture greater detail on updaterEnabled
  Restore old error functionality of prSelectorForCurrentBranch
  Change error handling on ReadBranchConfig to respect git Exit Codes
  fix: add back colon that I removed
  fix: actually read how MaxFunc work and simplify the code
  fix: padded display
  Collapse dryrun checks in ext bin upgrade
  Bump github.com/mattn/go-colorable from 0.1.13 to 0.1.14
  Rename test user in tests
  Change pr number in test
  Surface and handle error from ReadBranchConfig in parseCurrentBranch
  Directly stub headBranchConfig in Test_tryDetermineTrackingRef
  Refactor error handling in ReadBranchConfig to avoid panic
  Refine error handling of ReadBranchConfig
  Add test for empty BranchConfig in prSelectorForCurrentBranch
  ...
2025-01-13 20:38:00 -08:00
Tyler McGoffin
e4320ccc4b Directly stub headBranchConfig in Test_tryDetermineTrackingRef 2025-01-09 11:58:33 -08:00
Tyler McGoffin
bf6fdbdfd2 Remove named returns from ReadBranchConfig and surface errors 2025-01-07 13:54:43 -08:00
Frederick Zhang
4254818dbd
Find push remote using branch.<name>.pushRemote and remote.pushDefault
When using a push.default = current triangular workflow, apart from
using @{push} to determine the remote branch name, we should also follow
the

1. branch.<name>.pushRemote
2. remote.pushDefault
3. branch.<name>.remote

...list to determine which remote Git pushes to.
2025-01-07 10:22:39 +11:00
Frederick Zhang
0179381efd
Find PRs using @{push}
When using a push.default = current central workflow [1], we should use
@{push} instead to locate the remote branch.

In fact, @{push} covers most cases in push.default = upstream too. The
branch.<name>.merge is probably only needed when using RemoteURL and
different remote / local branch names.

[1] https://github.com/tpope/vim-fugitive/issues/1172#issuecomment-522301607
2025-01-07 10:18:01 +11:00
William Martin
8b5073d617 Move trackingRef into pr create package 2025-01-06 10:33:28 -06:00
William Martin
62ecb1c84d Make tryDetermineTrackingRef tests more respective of reality
Though it doesn't really matter, in practice upstream is always going to come before origin.
2025-01-06 10:33:28 -06:00
William Martin
57ba5e5608 Rework tryDetermineTrackingRef tests 2025-01-06 10:33:28 -06:00
William Martin
b8c167970b Avoid pointer return from determineTrackingBranch 2025-01-06 10:33:28 -06:00
William Martin
05764b8114 Don't use pointer for determineTrackingBranch branchConfig 2025-01-06 10:33:28 -06:00