Skip to content

Instantly share code, notes, and snippets.

@tamtom
Last active June 13, 2022 14:14
Show Gist options
  • Save tamtom/b3fa4119cbaebe444c750938782d8b52 to your computer and use it in GitHub Desktop.
Save tamtom/b3fa4119cbaebe444c750938782d8b52 to your computer and use it in GitHub Desktop.
#!/bin/zsh
source ~/.bash_profile
branch=$(git rev-parse --abbrev-ref HEAD)
git push origin $branch
# Getting the task data from Jira API
response=$(curl -s "${jira_url}/rest/api/2/issue/$branch" -u "$jira_access_token" | sed 's#\\n##g;s#\\#\\\\#g')
base_branch=$1
if [ -z "$base_branch" ]; then
base_branch=$(git show-branch | grep '*' | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//')
fi
# Parsing Jira task information
title=$(echo $response | jq -r '.fields.summary' | sed 's/^[ ]*//;s/[ ]*$//')
type=$(echo $response | jq -r '.fields.issuetype.name')
# prepare the pull request information
assign="${github_author}"
reviewers="${github_reviewers}"
# prepare the label of the pull request
if [ "$type" = "Story" ]; then
label='Story'
fi
if [ "$type" = "Sub-task" ] || [ "$type" = "Task" ]; then
label='Sub-task'
fi
if [ "$type" = "Bug" ] || [ "$type" = "Story bug" ]; then
label='BUG'
fi
if [[ "$base_branch" == *"release"* ]]; then
if [ -z "$label" ]; then
label='Release'
else
label=$label',Release'
fi
fi
# add PR title
if [ "$title" != "null" ]; then
echo "$branch $title" > PR_MESSAGE
fi
echo "" >> PR_MESSAGE
# Build PR description using the template, this section is cutomizable and up to you how to create it
cat .github/pull_request_template.md >> PR_MESSAGE
echo "[**$branch $title**]($jira_url/browse/$branch)" > TMP
sed -i -e '/Story Link/r TMP' PR_MESSAGE
# Append the commit messages in the description
git log -n 10 | grep $branch | sed "s# $branch#*#g" > TMP
sed -i -e '/Implementation Details/r TMP' PR_MESSAGE
cat PR_MESSAGE
if [ -z "$label" ]; then
hub pull-request -b $base_branch -F PR_MESSAGE --no-edit -o -r $reviewers -a $assign
else
hub pull-request -b $base_branch -F PR_MESSAGE --no-edit -o -r $reviewers -a $assign -l $label
fi
rm -f PR_MESSAGE
rm -f PR_MESSAGE-e
rm -f PR_MESSAGE_DESCRIPTION
rm -f TMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment