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

Provide gh cli Support to Revert Pull Request #6034

Open
duffenterprises opened this issue Aug 4, 2022 · 11 comments · May be fixed by #8826
Open

Provide gh cli Support to Revert Pull Request #6034

duffenterprises opened this issue Aug 4, 2022 · 11 comments · May be fixed by #8826
Labels
enhancement a request to improve CLI gh-pr relating to the gh pr command help wanted Contributions welcome

Comments

@duffenterprises
Copy link

Describe the feature or problem you’d like to solve

To support automation and CI/CD it would be beneficial for the GitHub CLI to support reverting a pull request equivalent to what the UI is able to accomplish.

Proposed solution

gh pr revert 416967111

Additional context

In a multi-contributor, pull-request managed repository there are limits to what linting/formating/plan (e.g. terraform plan) can achieve before attempting to deploy (e.g. terraform apply). To increase velocity, and minimize effort required by maintainers, it would be beneficial to be able to revert a PR following a failed build/deploy.

@duffenterprises duffenterprises added the enhancement a request to improve CLI label Aug 4, 2022
@cliAutomation cliAutomation added the needs-triage needs to be reviewed label Aug 4, 2022
@mislav mislav added blocked platform Problems with the GitHub platform rather than the CLI client and removed needs-triage needs to be reviewed labels Aug 4, 2022
@mislav
Copy link
Contributor

mislav commented Aug 4, 2022

Thanks for the feature request! Agreed that this would be useful, but I do not think there is an API to revert a merged PR. Until then, we cannot act on adding this to CLI.

In the meantime, you can use gh pr view to determine the merge commit for a PR and use git locally to revert that merge commit:

gh pr view PRNUM --json mergeCommit -q .mergeCommit.oid

@azizshamim
Copy link

azizshamim commented Aug 5, 2022

There's a revertResourcePath attribute in the pullrequest Object in the GraphQL API. Unsure if that's useful for request, but worth looking at.

@duffenterprises
Copy link
Author

@azizshamim @mislav Any chance there has been any progress here?

@vilmibm
Copy link
Contributor

vilmibm commented Jan 11, 2023

There's a revertResourcePath attribute in the pullrequest Object in the GraphQL API. Unsure if that's useful for request, but worth looking at.

This URL is for use in the browser; the best the CLI could do is link to it.

@colindembovsky
Copy link

colindembovsky commented Jan 12, 2023

One team is migrating from Gerrit and want to mimic some of the capabilities that Gerrit has. Gerrit has topics which are essentially multi-repo PRs. GitHub PRs are scoped to a single repo.

What they are planning to do is link a set of PRs (to simulate the topic construct). I think this request comes from their commit process - if they approve a topic, they will merge the set of PRs - but if something fails, they want to be able to revert the merge.

@mislav
Copy link
Contributor

mislav commented Jan 27, 2023

Update: the platform team just shipped a new API to revert a PR with:

mutation ($pr: ID!, $asDraft: Boolean = false, $title: String, $body: String) {
	revertPullRequest(
		input: {
			title: $title,
			body: $body,
			draft: $asDraft,
			pullRequestId: $pr,
		}
	) {
		revertPullRequest {
			url
		}
	}
}

You can already use this as so:

# reads the query from a file:
gh api graphql -F [email protected] -f 'pr=<PR-ID>'

How should we expose this as a command in gh?

  1. gh pr revert <PR>
  2. gh pr merge --undo <PR> (sort of like gh pr ready --undo)

@mislav mislav added help wanted Contributions welcome and removed blocked platform Problems with the GitHub platform rather than the CLI client labels Jan 27, 2023
@5HT2
Copy link

5HT2 commented Jan 30, 2023

I feel like gh pr revert <PR> makes more sense intuitively, as in the web UI 'revert' is shown separately akin to how 'close' is shown separately.

When you revert a PR, you're not inherently "undoing" the merge, you're rather making a new change that reverts the commit itself.
gh pr merge --undo might imply to some people that it will undo the state of the pull request / reopen it and so on. It could also be understood to mean restoring the branch to it's former state, as if you had force pushed an older commit back to entirely get rid of the commit history / the fact it was ever merged.

@mislav
Copy link
Contributor

mislav commented Jan 30, 2023

@5HT2: that's a good point. A new command revert it is then 👍

@duffenterprises
Copy link
Author

@mislav How does work prioritization work for gh cli. I noticed the help wanted but haven't contributed to this repo before.

@mislav
Copy link
Contributor

mislav commented Jan 30, 2023

Work prioritization looks like this: if something is tagged help wanted, that means that there should be enough information in the thread for an outside contributor to pick up the feature and produce a pull request. https://github.com/cli/cli/blob/trunk/.github/CONTRIBUTING.md

Eventually, our team might also pick up this work, but before we manage to get to it, anyone is welcome to!

@dtbell91
Copy link

dtbell91 commented May 7, 2024

What's needed to help the PR progress to being reviewed and (hopefully) merged?

I'm pretty interested in using this functionality after trying out the GraphQL approach with some success.

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.

9 participants