Skip to content

Instantly share code, notes, and snippets.

@Cheezmeister
Created March 12, 2019 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cheezmeister/896d3336da45ebaf160821697b11f93a to your computer and use it in GitHub Desktop.
Save Cheezmeister/896d3336da45ebaf160821697b11f93a to your computer and use it in GitHub Desktop.
#!/bin/sh
cd "$(git rev-parse --show-toplevel)" || exit
usage() {
echo "Usage: $0 <featurebranch|pullrequest>"
echo ""
echo "Example:"
echo "$0 fb SP-1234"
echo "./write-the-codes.sh"
echo "$0 pr"
}
# TODO Read meta from JIRA ticket
# curl https://$JIRA_DOMAIN/rest/api/latest/issue/$ticket --user $JIRA_USER:$JIRA_TOKEN
case $1 in
'featurebranch' | 'fb')
ticket=${2:-$(pbpaste)}
echo "Descriptive branch name (no spaces, see https://stackoverflow.com/a/3651867):"
read -r description
branchname="$USER-$ticket-$description"
git checkout -b "$branchname"
git push --set-upstream origin "$branchname"
# TODO Start JIRA ticket
;;
'pullrequest' | 'pr')
ticket=$(git rev-parse --abbrev-ref HEAD | cut -d '-' -f 2-3)
url="https://$JIRA_DOMAIN/browse/$ticket"
prnotesfile="pr-$ticket.md"
cp PULL_REQUEST_TEMPLATE.md "$prnotesfile"
badge="[![badge](https://img.shields.io/badge/$ticket-blue.svg)]($url)"
ex -s -c "1normal A $badge" -c "1normal O$ticket: THIS_IS_THE_TITLE_OF_YOUR_PR " -cx "$prnotesfile"
shift
hub pull-request --edit --file "$prnotesfile" --browse "$@" || cp .git/PULLREQ_EDITMSG "$prnotesfile"
# TODO Advance JIRA status
;;
*)
usage
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment