Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a gh pr update command corresponding to the API call / button on the Web UI #8426

Open
tgoodsell-tempus opened this issue Dec 6, 2023 · 6 comments · May be fixed by #8953
Open

Add a gh pr update command corresponding to the API call / button on the Web UI #8426

tgoodsell-tempus opened this issue Dec 6, 2023 · 6 comments · May be fixed by #8953
Labels
enhancement a request to improve CLI gh-pr relating to the gh pr command help wanted Contributions welcome

Comments

@tgoodsell-tempus
Copy link

tgoodsell-tempus commented Dec 6, 2023

Describe the feature or problem you’d like to solve

The GH web interface and REST API support a PR "update" function, which does a merge or a rebase, with the rest API only supporting the merge commit option.

See: Keeping You Pull Request In Sync

It would be nice to have this function available in the CLI toolkit, meaning the direct GH API version of this, not a pseudo-update via doing the various git syncing and updating locally.

Proposed solution

Introduce a gh pr update command which:

  • Leverages the GH REST API version of this: Update A Pull Request Branch
    • The GraphQL API appears to support both the rebase and merge options, see: Update Pull Request Branch, this could be a good alternative to the REST API provided the maintainers are OK with using it over the REST call.
  • After the update is performed and the API tells us it's succeeded, pull/sync the local branch with the changed upstream branch

Additional context

As mentioned above, my personal preference is the update itself occurs using the API object, instead of doing the local only version of a merge/rebase on the base branch. Since I'm trying to mimic the Web UI button, the reasons that exists versus Github telling us to "get good" at doing branch updates I would apply to this command as well.

@tgoodsell-tempus tgoodsell-tempus added the enhancement a request to improve CLI label Dec 6, 2023
@cliAutomation cliAutomation added the needs-triage needs to be reviewed label Dec 6, 2023
@andyfeller andyfeller added the discuss Feature changes that require discussion primarily among the GitHub CLI team label Dec 6, 2023
@maco
Copy link

maco commented Dec 18, 2023

And a benefit of it doing it using the GH API instead of locally is that when you do it in the GH UI, it doesn't clear your approvals, whereas if you update the branch locally and push, I'm pretty sure it does.

@williammartin williammartin added the gh-pr relating to the gh pr command label Jan 19, 2024
@williammartin
Copy link
Member

Hey @tgoodsell-tempus, thanks for opening this and sorry about the slow response, December was a busy time and then we were into the holidays. We're catching up on untriaged issues at the moment.

I think some of the behaviour you're describing can be emulated with gh repo sync but I can definitely see why it would be natural to find an equivalent to the UI under gh pr as a first class pr behaviour.

The REST API equivalent to the GQL mutation would appear to be https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#update-a-pull-request-branch.

We're a bit hesitant to make changes around gh pr at the moment because there's so many issues and it might be that the whole command needs a bit of a redesign. On the other hand, this one feels fairly straightforward and self-contained so maybe we'll open it up to community contributions. I'll discuss with the team!

@andyfeller
Copy link
Contributor

And a benefit of it doing it using the GH API instead of locally is that when you do it in the GH UI, it doesn't clear your approvals, whereas if you update the branch locally and push, I'm pretty sure it does.

@maco : it is a little nuanced as it depends on how you setup branch protection rules and/or repository rulesets

Dismiss stale pull request approvals when new commits are pushed and/or Require approval of the most recent reviewable push

It sounds like you might have worked with some repositories that were inconsistently configured.

@williammartin williammartin added discuss Feature changes that require discussion primarily among the GitHub CLI team and removed discuss Feature changes that require discussion primarily among the GitHub CLI team labels Jan 22, 2024
@williammartin
Copy link
Member

We discussed this and think it would be a good command to have. To me, it feels self contained and low risk. I'd be interested in opening this up to the community to implement. WDYT @andyfeller ?

@mxie
Copy link

mxie commented Jan 31, 2024

We discussed this and think it would be a good command to have. To me, it feels self contained and low risk. I'd be interested in opening this up to the community to implement. WDYT @andyfeller ?

Confirmed with Andy that we're good to let folks pick this up if they're interested!

@mxie mxie added help wanted Contributions welcome and removed needs-triage needs to be reviewed discuss Feature changes that require discussion primarily among the GitHub CLI team labels Jan 31, 2024
@babakks babakks linked a pull request Apr 10, 2024 that will close this issue
@babakks
Copy link
Contributor

babakks commented Apr 10, 2024

@williammartin @andyfeller @mxie I just pushed a PR to add the pr update command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement a request to improve CLI gh-pr relating to the gh pr command help wanted Contributions welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants