Rightpoint / ios-template

A `cookiecutter` template for iOS projects
MIT License
94 stars 26 forks source link

Git commit automation #146

Open armcknight opened 4 years ago

armcknight commented 4 years ago

... we would need a way to bootstrap these into a developer's local clone, via e.g. a make init as mentioned in #129

armcknight commented 4 years ago

We can even dispense with the template if we just use the prepare-commit-msg hook to write the entire thing. Experimenting locally, I wound up with

#!/bin/bash

# get branch name which should be formatted as <project id>-<ticket number>-<friendly name with words delimited by hyphens>, remove any fix|feat|etc/<username> path prefixes
BRANCH_NAME=$(basename $(git rev-parse --abbrev-ref HEAD))

# separated by hyphens, get the first two groups, which should be project id and ticket number, leave as hyphenated
TICKET_ID=$(echo $BRANCH_NAME | cut -d'-' -f 1,2)

# separated by hyphens, remove first two groups (project id, ticket number) and for the remainder, replace hyphens with spaces
TICKET_NAME=$(echo $BRANCH_NAME | cut -d'-' -f3- | sed s/\-/\ /g)

TICKET_URL="https://raizlabs.atlassian.net/browse/$TICKET_ID"

PREPENDED_MSG=$(cat <<COMMIT_MESSAGE_TEMPLATE

##################################
# So, you want to make a commit? #
##################################

# Please take the time to create a great commit for the benefit of 
# future you and other maintainers! See the guidelines for more 
# information at https://rpo365.sharepoint.com/:w:/r/sites/RP-Practices/Shared%20Documents/Product%20Engineering/Development%20Guides/Git%20Workflow.docx?d=wfb5201b4c39947b5b5f20a98a2760033&csf=1&e=479EbP.

###########################################################################################
# Commit Subject (50 chars): <feat|fix|test|refact|style|docs|chore>: <short description> #
###########################################################################################

subject

################################################################
# Commit Body (long-form description wrapped to 72 characters) #
################################################################

# <body here>

######################################################################################
# Automated ticket info/url injection (from .git/hooks/prepare-commit-msg,           #
# maintained at https://github.com/raizlabs/ios-template/scripts/prepare-commit-msg) #
######################################################################################

$TICKET_NAME: $TICKET_URL

COMMIT_MESSAGE_TEMPLATE
)

echo "$PREPENDED_MSG" > $1

which prepopulated the commit message like so running on my branch:


##################################
# So, you want to make a commit? #
##################################

# Please take the time to create a great commit for the benefit of 
# future you and other maintainers! See the guidelines at for more 
# information at https://rpo365.sharepoint.com/:w:/r/sites/RP-Practices/Shared%20Documents/Product%20Engineering/Development%20Guides/Git%20Workflow.docx?d=wfb5201b4c39947b5b5f20a98a2760033&csf=1&e=479EbP.

###########################################################################################
# Commit Subject (50 chars): <feat|fix|test|refact|style|docs|chore>: <short description> #
###########################################################################################

subject

################################################################
# Commit Body (long-form description wrapped to 72 characters) #
################################################################

# <body here>

######################################################################################
# Automated ticket info/url injection (from .git/hooks/prepare-commit-msg,           #
# maintained at https://github.com/raizlabs/ios-template/scripts/prepare-commit-msg) #
######################################################################################

roundtrip success: https://raizlabs.atlassian.net/browse/XCI-4179
armcknight commented 4 years ago

Need to do more work on the above to work with the following: