Created
October 27, 2022 08:29
-
-
Save mattak/01969becb1c561120f25b2c0c025a5d8 to your computer and use it in GitHub Desktop.
github pull request creation script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# optparse | |
if [ $# -ge 1 ]; then | |
SOURCE_BRANCH=$1 | |
else | |
echo "ERROR: source branch not specified" | |
exit 1 | |
fi | |
# variables | |
GIT_URL=$(git config --get remote.origin.url) | |
GIT_URL=${GIT_URL/ssh:\/\//http:\/\/} | |
GIT_URL=$(echo $GIT_URL | perl -pne 's|git@([^\:]+):|https://$1/|g') | |
GIT_URL=${GIT_URL/.git/} | |
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
if [[ $GIT_BRANCH =~ ^epic/ ]]; then | |
IS_EPIC=1 | |
GH_OPTION_LABEL="--label Epic" | |
else | |
IS_EPIC=0 | |
GH_OPTION_LABEL="" | |
fi | |
echo "IS_EPIC=$IS_EPIC" | |
# create issue number | |
GIT_ISSUE_NUMBER=$(echo "$GIT_BRANCH" | perl -pne 's|^.+/#(\d+).*$|\1|g') | |
echo ISSUE: $GIT_ISSUE_NUMBER | |
if [ "$GIT_ISSUE_NUMBER" != "" ]; then | |
GIT_TITLE=$(gh issue view $GIT_ISSUE_NUMBER | head | grep -E 'title:' | perl -pne 's|^title:\s+||g') | |
GIT_TITLE=$(echo "${TITLE_TAG}#$GIT_ISSUE_NUMBER $GIT_TITLE") | |
if [ $IS_EPIC -eq 1 ]; then | |
GIT_TITLE="[EPIC] $GIT_TITLE" | |
fi | |
GIT_BODY=$(cat << __BODY__ | |
# 概要 | |
# 確認事項 | |
- [ ] 実機確認 | |
# 参照 | |
- #${GIT_ISSUE_NUMBER} | |
__BODY__ | |
) | |
gh pr create --draft $GH_OPTION_LABEL --assignee "mattak" --base "$SOURCE_BRANCH" --title "$GIT_TITLE" --body "$GIT_BODY" | tee /tmp/git-prc.log | |
cat /tmp/git-prc.log | grep https:// | xargs chrome | |
else | |
echo "ERROR: git issue number not found" | |
exit 1 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment