-
Notifications
You must be signed in to change notification settings - Fork 425
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
EXPERIMENT: tool to automatically create backport PRs #21060
Conversation
Experimental, use at your own risk. Uses purely the GitHub API to avoid any problems running local `git` commands.
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.
Looks very handy!
@@ -0,0 +1,70 @@ | |||
#!/bin/bash | |||
|
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.
I tend to always use set -euo pipefail
(IIRC, one fails on undefined variables, one makes the result of a pipe fail if any part fails, and I can't remember the other one). I think that'd be safer since there are some pipes in there.
PR_URL=$(curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" $REPOSITORY/pulls \ | ||
-d "{\"title\":\"${PR_TITLE}\", \"body\":\"${PR_BODY}\", \"head\":\"${NEW_BRANCH}\", \"base\":\"${TARGET_BRANCH}\"}" | jq .html_url) | ||
|
||
echo "Successfully created backport branch and pull request: $PR_URL" |
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.
Hmm I gave this a try and it exited with this:
$ ./backport.sh ef07a406cc8dbccb4914bbd27631df74e5b13b49 minor-fleet-v4.55.0
GitHub token not provided, attempting to retrieve it using gh CLI...
Successfully created backport branch and pull request: null
It did create the branch, but not the PR, and when I go ahead and create the PR it seems like both are identical. Not sure what step went wrong exactly though.
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.
Likely something between lines 51 and 60.
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.
thank you for giving it a try!! 🤗 I have been testing it with a private repo, will see if something is different when using fleetdm/fleet
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.
it fails because the message has double quotes! we should account for this case and also fail the script if one of the requests fails. TY!!
-d '{"message": "Backport: Bugfix: list host software "Available for install" filter must show installers that have an install request on the host (#21083)", "tree": "5128a2a70d34654de0b875ce0d77ce87e874d23b", "parents": ["64e97b3a66f954e8ba92242a66990890375dfec3"]}'
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.
Ahhh! Makes sense! Yeah I think the set -euo pipefail
would've failed the script at that point (assuming curl did return an error exit code). There may be an easy way to JSON-encode the message with jq
so that special chars don't break the commands?
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.
Looks like this would do it?
$ echo 'An "Available" filter' | jq -R '.'
"An \"Available\" filter"
Experimental, use at your own risk. Uses purely the GitHub API to avoid any problems running local
git
commands.