update default upstream when forking repo during PR creation#10458
update default upstream when forking repo during PR creation#10458andyfeller merged 3 commits intocli:trunkfrom
Conversation
update default upstream when forking repo remove unnecessary variable
0605884 to
5004ba2
Compare
|
Thanks for opening this PR and contributing to the GitHub CLI, @daviddl9! I'm starting to review these changes while doing a bit of manual testing to understand the new experience. Will leave my notes and review shortly. |
Manual testing
|
|
Popping in, here: that Bash script looks like a good candidate for an acceptance test around this. |
This commit brings this code more into alignment with other places: 1. Using a local variable for upstream remote name instead of hardcoding everywhere 2. Raising error raised by setting default remote 3. Removing condition for displaying upstream default message 4. Bring message logic more inline with other places within function
andyfeller
left a comment
There was a problem hiding this comment.
Looks good, @daviddl9! ✨
In an effort to keep the train rolling, I commit a few enhancements based on the suggestions below. Some of the other idle thoughts are things we can revisit in the future.
| if didForkRepo { | ||
| gitClient.SetRemoteResolution(context.Background(), "upstream", "base") | ||
| if opts.IO.IsStdinTTY() && opts.IO.IsStdoutTTY() { | ||
| cs := opts.IO.ColorScheme() | ||
| stderr := opts.IO.ErrOut | ||
| fmt.Fprintf(stderr, "%s Repository %s set as the default repository. To learn more about the default repository, run: gh repo set-default --help\n", cs.WarningIcon(), cs.Bold(ghrepo.FullName(headRepo))) | ||
| } | ||
| } |
There was a problem hiding this comment.
Suggestions
Out of all of following idle thoughts, I think only a handful are reasonable to knock out here now versus waiting for new issues being raised:
- Remove
stdinrequirement for messaging - Use local variable versus hardcoding remote name
- Return the error raised by setting default remote
Notes
Some of my idle thoughts reviewing this logic:
- Why does
stdinbeing TTY affect whether we output this message? - How does such conditional logic apply to the
Added ... as remotemessage? - When do we use a variable for the remote name versus hardcoding this everywhere?
- How does this differ from other places in code where we handle this?
- Does this logic need to ensure no other remote is marked as default before setting
upstream?
TTY affecting messaging
It seems like gh repo fork care about stdin, stdout, stderr...
Line 187 in ae2f4b7
Lines 380 to 383 in ae2f4b7
whereas gh repo clone just cares about stdout being TTY:
cli/pkg/cmd/repo/clone/clone.go
Lines 217 to 221 in ae2f4b7
Definitely want to revisit where different types or classes of messages are displayed so we had a little more consistency. In the meantime, I assume gh pr create would follow the same behavior as gh repo clone without factoring in stdin if we even bother to check.
Setting and unsetting
My main concern with the changes as they stand is comparing this versus gh repo set-default which checks func (r Remotes) ResolvedRemote() (*Remote, error) to determine if it should unset a remote before setting a new one 🤔
cli/pkg/cmd/repo/setdefault/setdefault.go
Lines 228 to 242 in ae2f4b7
It feels there is an edge case that can emerge around upstream remote separately of the server-side repository forking the command does. However, let's see about users reporting errors before dealing with that concern.
Other places where we set default repository
Just because I know this messaging is in a few different places, I always look at how consistent our behavior is.
cli/pkg/cmd/repo/clone/clone.go
Lines 209 to 221 in ae2f4b7
Lines 372 to 383 in ae2f4b7
@cli/code-reviewers : Perhaps its worth discussing at our next retro about when we write out |
|
Hey @andyfeller thanks for taking the time to look through the PR! Mostly agree with the ideas that you had in mind. Had a little suggestion about how we handle the case when setting the default upstream fails: The core operation here is creating a PR. Setting the default upstream is a secondary, convenience operation that helps with future workflows but isn't critical to the PR's existence or functionality. Therefore, I'm thinking a warning would be more appropriate here since:
What do you think? Maybe something along the lines of: |
🤔 Fair concern; let's see some of the other places we're doing this: Lines 62 to 67 in 8365e0b cli/pkg/cmd/repo/rename/rename.go Lines 159 to 168 in 8365e0b @daviddl9 : what is the likelihood this will fail leaving this in a bad state? |
|
@andyfeller thanks for looking into this and for the prompt response! fair question - yeah realistically although the likelihood of failure is small, in the rare event that it does fail it could lead to a confusing / frustrating user experience where the core PR creation fails because of this. If you're ok, I could put up another small PR to change this? |
@daviddl9 : I'm going to bring this back into the issue so we can discuss it with the user who reported this as well as my fellow maintainer for discussion. It isn't clear cut whether this should be a hard or soft error; I personally think rather that this should be a hard error. Generally, we've adopted a "let's wait for this to emerge as a problem before we fix" but let's bubble this up there. UPDATE: See #10277 (comment) |
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [cli/cli](https://github.com/cli/cli) | minor | `v2.67.0` -> `v2.68.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.68.0`](https://github.com/cli/cli/releases/tag/v2.68.0): GitHub CLI 2.68.0 [Compare Source](cli/cli@v2.67.0...v2.68.0) #### What's Changed ##### ✨ Features - \[gh repo view] Improve error message for forked repo by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10334 - Add signer-digest, source-ref, and source-digest options for `gh attestation verify` by [@​malancas](https://github.com/malancas) in cli/cli#10308 - \[gh pr checkout] Add --no-tags option to git fetch commands in checkout by [@​latzskim](https://github.com/latzskim) in cli/cli#10479 - \[`gh issue/pr comment`] Add `--create-if-none` and prompts to create a comment if no comment already exists by [@​latzskim](https://github.com/latzskim) in cli/cli#10427 - \[gh cache delete --all] Add `--succeed-on-no-caches` flag to return exit code 0 by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10327 - \[gh release create] Fail when there are no new commits since the last release by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10398 - update default upstream when forking repo during MR creation by [@​daviddl9](https://github.com/daviddl9) in cli/cli#10458 ##### 🐛 Fixes - Refactor `GetLocalAttestations` and clean up custom registry transport by [@​malancas](https://github.com/malancas) in cli/cli#10382 - Check `GH_REPO` too in addition to `--repo` for disambiguation by [@​williammartin](https://github.com/williammartin) in cli/cli#10539 - (Fixes `gh secret` subcommands not working outside of a repository) - Fix unhandled panic in FindWorkflow and add tests by [@​jtmcg](https://github.com/jtmcg) in cli/cli#10521 - Fix checkout when URL arg is from fork and cwd is upstream by [@​williammartin](https://github.com/williammartin) in cli/cli#10512 - \[gh api] Escape package name (URL encoding) for packages endpoint by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10384 - Fix `remoteResolver` caching issue by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10456 - Fix gh project item-edit to allow --number 0 as a valid value by [@​aryanbhosale](https://github.com/aryanbhosale) in cli/cli#10417 - Add mutex to fix race in attestation test client by [@​codysoyland](https://github.com/codysoyland) in cli/cli#10439 - Base64 decode GPG passphrase in deployment workflow by [@​BagToad](https://github.com/BagToad) in cli/cli#10546 ##### 📚 Docs & Chores - Deep Dive Document Release Process by [@​williammartin](https://github.com/williammartin) in cli/cli#10503 - Inconsistent format of examples in help text by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10508 - Inconsistent format of description of flags (starting with lowercase letter) by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10507 - Update Go version to 1.23 in CONTRIBUTING.md by [@​williammartin](https://github.com/williammartin) in cli/cli#10504 - Fix minor auth login help typo by [@​williammartin](https://github.com/williammartin) in cli/cli#10501 - docs: document how to revoke `gh` OAuth tokens in `auth logout`'s help by [@​BagToad](https://github.com/BagToad) in cli/cli#10490 - chore: update codespaces Go version by [@​BagToad](https://github.com/BagToad) in cli/cli#10491 - Allow injection of TUFMetadataDir in tests by [@​williammartin](https://github.com/williammartin) in cli/cli#10478 - refactor: use a more straightforward return value by [@​beforetech](https://github.com/beforetech) in cli/cli#10489 - Use subtests in attestation verification integration tests by [@​williammartin](https://github.com/williammartin) in cli/cli#10463 - Fix typo in README by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10445 - Update usage to lower-kebab-case by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10447 - Standardize URLs by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10429 - Remove trailing whitespace by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10430 #####Dependencies - Bump actions/attest-build-provenance from 2.2.0 to 2.2.2 by [@​dependabot](https://github.com/dependabot) in cli/cli#10518 - Bump github.com/go-jose/go-jose/v4 from 4.0.2 to 4.0.5 by [@​dependabot](https://github.com/dependabot) in cli/cli#10499 - Bump github.com/spf13/pflag from 1.0.5 to 1.0.6 by [@​dependabot](https://github.com/dependabot) in cli/cli#10338 </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:eyJjcmVhdGVkSW5WZXIiOiIzOS4xODYuMCIsInVwZGF0ZWRJblZlciI6IjM5LjE4Ni4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
This PR updates the behaviour to set the default upstream when forking a repo during PR creation. It ensures that the behaviour when performing a fork during PR creation remains consistent with
gh repo fork.Closes #10277
This bash script can be used to verify these changes: