-
-
Save Cheezmeister/24bea1eb89a5ce5b3ba7791afd093a74 to your computer and use it in GitHub Desktop.
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 | |
cd "$(git rev-parse --show-toplevel)" || exit | |
slack_channel=${OTTO_SLACK_CHANNEL:-'#development'} | |
# For best results, grab the following packages on OSX | |
# brew install hub go-jira slack-cli moreutils | |
usage() { | |
echo "Usage: $0 <featurebranch|pullrequest|jira|pullrequest|badge|deploy|promote>" | |
echo "" | |
echo "Example:" | |
echo "$0 fb SP-1234" | |
echo "./write-the-codes.sh" | |
echo "$0 j # Make sure we're addressing requirements" | |
echo "./write-moar-codes.sh" | |
echo "$0 pr" | |
} | |
case $1 in | |
'featurebranch' | 'fb') | |
ticket=${2:-$(pbpaste)} | |
ticket=${ticket##*/} | |
command -v jira && jira view "$ticket" | grep summary | |
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" | |
command -v jira && jira transition --noedit "In Progress" "$ticket" || echo "Couldn't start ticket" | |
;; | |
'pullrequest' | 'pr') | |
branchname=$(git rev-parse --abbrev-ref HEAD) | |
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" || cp .github/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" | |
[[ -e .git/PULLREQ_EDITMSG ]] && hub pull-request --edit --browse | |
shift | |
hub pull-request --edit --file "$prnotesfile" --browse "$@" || exit 1 | |
pr_url=$(hub pr list -h "$branchname" -f '%U') | |
pr_desc=$(hub pr list -h "$branchname" -f '%t') | |
command -v jira && jira transition --noedit "In Review" "$ticket" || echo "Couldn't advance ticket" | |
command -v jira && jira comment "$ticket" --noedit --comment "PR is up: $pr_url" || echo "Couldn't comment with PR URL on ticket" | |
# Post to slack | |
command -v slack && echo "Post to Slack? [Y/n]" && read -r yn && [[ ! $yn =~ ^[Nn]$ ]] && { | |
echo 'What does this PR do? ' | |
read -r do_the_thing | |
echo 'What are the line deltas?' | |
read -rp '[+x/-y] ' deltas | |
slack chat send --channel "$slack_channel" --text ":bob_ross: *PR to $do_the_thing ($deltas)*: $pr_url" | |
slack chat send --channel "$slack_channel" --text "> $pr_desc" | |
} || echo "Skipping slack post to #development; see https://github.com/rockymadden/slack-cli#installation" | |
;; | |
'deploy' | 'd') | |
ticket=$(git rev-parse --abbrev-ref HEAD | cut -d '-' -f 2-3) | |
git checkout master | |
git pull && time bin/deploy staging 2>&1 | ts | tee deploy.log && say "Deploy to staging complete" | |
[[ $? ]] && echo "Transitioning ticket" && jira transition --noedit "Ready for QA" "$ticket" || echo "Couldn't advance ticket" | |
;; | |
'promote' | 'prod' | 'p') | |
ticket=${2:-$(pbpaste)} | |
ticket=${ticket:-$(git rev-parse --abbrev-ref HEAD | cut -d '-' -f 2-3)} | |
;; | |
'jira' | 'j') | |
ticket=$(git rev-parse --abbrev-ref HEAD | cut -d '-' -f 2-3) | |
url="https://$JIRA_DOMAIN/browse/$ticket" | |
open "$url" | |
;; | |
'badge' | 'b') | |
ticket=${2:-$(pbpaste)} | |
url="https://$JIRA_DOMAIN/browse/$ticket" | |
badge="[![badge](https://img.shields.io/badge/$ticket-blue.svg)]($url)" | |
echo "$badge" | |
;; | |
*) | |
usage | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment