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

EXPERIMENT: tool to automatically create backport PRs #21060

Closed
wants to merge 1 commit into from

Conversation

roperzh
Copy link
Contributor

@roperzh roperzh commented Aug 5, 2024

Experimental, use at your own risk. Uses purely the GitHub API to avoid any problems running local git commands.

Experimental, use at your own risk. Uses purely the GitHub API to avoid
any problems running local `git` commands.
@roperzh roperzh requested a review from a team August 5, 2024 19:24
Copy link
Member

@mna mna left a 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

Copy link
Member

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"
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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"]}'

Copy link
Member

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?

Copy link
Member

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"

@roperzh roperzh marked this pull request as draft August 9, 2024 15:36
@roperzh roperzh closed this Oct 11, 2024
@roperzh roperzh deleted the experiment-auto-backport branch October 11, 2024 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants