Skip to content

Instantly share code, notes, and snippets.

@Cheezmeister
Last active March 8, 2019 19:59
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/2e13588dfb693dfc5765c11349fd9074 to your computer and use it in GitHub Desktop.
Save Cheezmeister/2e13588dfb693dfc5765c11349fd9074 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)
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
@NJAldwin
Copy link

fyi some shellcheck feedback (if you've not used shellcheck, brew install shellcheck. it's fantastic for shell scripts):

$ shellcheck myscript
 
Line 3:
cd $(git rev-parse --show-toplevel)
^-- SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
   ^-- SC2046: Quote this to prevent word splitting.

Did you mean: (apply this, apply all SC2164)
cd $(git rev-parse --show-toplevel) || exit
 
Line 19:
  read description
  ^-- SC2162: read without -r will mangle backslashes.
 
Line 20:
  git checkout -b $USER-$description.$ticket
                  ^-- SC2086: Double quote to prevent globbing and word splitting.
                        ^-- SC2086: Double quote to prevent globbing and word splitting.
                                     ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
  git checkout -b "$USER"-"$description"."$ticket"
 
Line 28:
  cp PULL_REQUEST_TEMPLATE.md $prnotesfile
                              ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
  cp PULL_REQUEST_TEMPLATE.md "$prnotesfile"
 
Line 32:
  ex -sc "1normal A $badge" -cx $prnotesfile
                                ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
  ex -sc "1normal A $badge" -cx "$prnotesfile"
 
Line 33:
  hub pull-request --edit --file $prnotesfile --browse
                                 ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
  hub pull-request --edit --file "$prnotesfile" --browse

$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment