Skip to content

Instantly share code, notes, and snippets.

@dryaz
Created June 16, 2023 16:25
Show Gist options
  • Save dryaz/4a9744e965cd03ad7bf97664be96eea3 to your computer and use it in GitHub Desktop.
Save dryaz/4a9744e965cd03ad7bf97664be96eea3 to your computer and use it in GitHub Desktop.
Create PR with help of github CLI with body and reviewers
#!/bin/sh
while [[ "$#" -gt 0 ]]; do
case $1 in
-b|--base) baseBranch="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
[[ -z "$baseBranch" ]] && {
echo "Error: Provide base branch with -b or --base";
echo "Possible branch you're looking for:"
echo " develop"
git branch | grep rc/
exit 1;
}
title=$(git log -1 --pretty=format:%s)
fullMessage=$(git log -1 --pretty=format:%b)
# This relies on the link to the issue in your tracker which could be created via commit-msg hook
# chk: https://gist.github.com/dryaz/6e55f55ffad6aeb188032e9481f78a45
url=$(echo $fullMessage | egrep -o 'https?://[^ ]+')
gh pr create --title "$title" --body "$url" --base $baseBranch --reviewer {reviewer1},{reviewer2}...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment