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 pr update
command
#8953
base: trunk
Are you sure you want to change the base?
Add pr update
command
#8953
Conversation
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
@williammartin This PR is actually my second (and simpler) approach to add the Unfortunately, this wasn't easily possible because the updated |
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally this looks excellent. Really easy to read top to bottom and great test coverage. However, there is some surprising behaviour that I think we need to address somehow.
Surprising Behaviour
Merging
There's some surprising behaviour here in my mind around updating branches that are already up to date. For example,
#9033, which was 1 commit ahead and 0 commits behind trunk
when I ran gh pr update 9033
3 times with the result being:
I fixed this with gh pr update --rebase 9033
which removed the merge commits (but also did something unexpected documented below):
Rebase
Now for the strange --rebase
behaviour:
After rebasing with gh pr update --rebase 9033
, I would not anticipate changes to the commit sha either:
What's going on?
For some reason that I will have to ask about internally, the API that powers these operations acts differently than git merge
or git rebase
which say Already up to date
and no-op.
What should we do?
The Web UI only shows this button when the branch is out of date:
Although it's an extra network hop, it seems like the right thing to do is to check whether our PR branch is actually behind and only then request the mutation.
In the meantime I'm going to see if I can get an answer from the team that owns the API.
I spoke to the API team internally and they are going to look at whether there should be some changes here. It appears this behaviour could also occur if you clicked the Let's proceed with adding a check that there is indeed work to be done before sending the mutation, thanks. |
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
@williammartin Thanks for the investigation. I added the check by using the |
Signed-off-by: Babak K. Shandiz <[email protected]>
@williammartin I just QA-ed the PR with the following script and it worked with the merge (not rebase) approach. That is, the first call updated the branch and second call resulted in an "already up-to-date" message. But when I tried with the
UPDATE I think it's a timing issue and the backend needed some time to process the changes. When I added a 30-second sleep before calling the QATo run this script, you need to build the #!/usr/bin/env sh
set -e
_tmp=/tmp
_repo=gh-some-repo
_gh=$(pwd)/bin/gh
_pwd=$(pwd)
cleanup () {
cd $_pwd
ARG=$?
rm -rf "$_tmp/$_repo"
gh repo delete --yes $_repo
exit $ARG
}
trap cleanup EXIT
cd $_tmp
$_gh repo create --private --add-readme $_repo
$_gh repo clone $_repo
cd $_repo
git checkout -b pr-branch
echo "updated in pr branch" > README.md
git commit -am 'change in pr'
git push -u origin pr-branch
$_gh pr create --fill --title "test" --body ''
git checkout main
touch NEW.md
echo "new file on main" > NEW.md
git add NEW.md
git commit -am 'change on main'
git push -u origin main
git checkout pr-branch
# This sleep helps with the "rebase not prepared" API error.
sleep 30
# This should result in "PR branch update"
$_gh pr update
# This should result in "PR branch already up-to-date"
$_gh pr update |
Signed-off-by: Babak K. Shandiz <[email protected]>
@williammartin Also, when there's a merge conflict, we just print the API error, which is:
I'm not sure how we can detect this specific error and display it in a nicer way. UPDATE I checked the |
This PR adds the new
pr update
command, to update a PR branch with the latest changes of its base. Under the hood, we use theupdatePullRequestBranch
mutation.Fixes #8426
Details
The command doc is:
QA
I was able to QA the changes using the script below. This should be run at the repo's root directory, with the binary at
bin/gh
. Note that the script will nevertheless clean up on exit.