Skip to content

Instantly share code, notes, and snippets.

@ognus
Created February 22, 2016 10:49
Show Gist options
  • Save ognus/146d849177d571e1f845 to your computer and use it in GitHub Desktop.
Save ognus/146d849177d571e1f845 to your computer and use it in GitHub Desktop.
Bash script for auto pushing current git branch and creating a Github PR with JIRA link in description
#!/bin/bash
#
# Usage: gitpr "My PR title"
#
# If branch name follows this convention: anything_JIRAPROJECT-TASKID then link to JIRA
# task is added in PR's description.
#
# This script requires https://hub.github.com/ to be installed.
#
JIRA_PROJECT_URL="https://[YOUR-PROJECT].atlassian.net"
BRANCH=`git rev-parse --abbrev-ref HEAD`
TASK=`echo $BRANCH | perl -pe 's|.*?([A-Z]+-[0-9]+)|\1|'`
JIRA="JIRA: ${JIRA_PROJECT_URL}/browse/${TASK}"
if [ "$BRANCH" = "master" ]; then
echo "Can't make a PR out of master, it's not a feature branch."
else
if [ "$1" = "" ]; then
echo "You have to specify a PR title."
else
PR_TITLE=$1
fi
if [ "$BRANCH" != "$TASK" ]; then
PR_DESC=$JIRA
fi
fi
if [ "$PR_TITLE" != "" ]; then
git push origin ${BRANCH}
echo -e "${PR_TITLE}\n\n${PR_DESC}" | hub pull-request -F -
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment