-
-
Save c2k/49729ac3d9d63a40c305 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
# Pivotal Tracker Ticket Extraction | |
# ================================= | |
# Extract Pivotal Tracker ticket ID from branch name and prepend to commit | |
# message for GitHub hook. | |
# | |
# Takes a commit message like: "A commit comment" for branch "bug-1234-hello" | |
# and changes it to: "A commit comment [#1234]" for easier commit ticket | |
# updates. | |
# | |
# Installation | |
# ============ | |
# 1. Add this snippet to: `<REPO>/.git/hooks/prepare-commit-msg` | |
# 2. Make sure to `chmod a+x <REPO>/.git/hooks/prepare-commit-msg` to make the | |
# code actually executable. | |
# | |
MSG_FILE=$1 | |
# Define a Pivotal Tracker ID as having 4+ consecutive digits. | |
PIVOTAL_RE="[0-9]{4,}" | |
# Infer our branch and an ID. | |
BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
BRANCH_ID=$(echo "${BRANCH}" | egrep -o "\-${PIVOTAL_RE}\-" | egrep -o "${PIVOTAL_RE}") | |
# Check if the commit message **already** has a Pivotal ID. | |
EXISTING_ID=$(egrep -o "[.*\#${PIVOTAL_RE}.*]" $MSG_FILE | egrep -o "${PIVOTAL_RE}") | |
# If there is a branch ID and not a commit message ID, then add the branch ID. | |
if [ -n "${BRANCH_ID}" ] && [ -z "${EXISTING_ID}" ]; then | |
echo "[#${BRANCH_ID}]" >> "${MSG_FILE}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works with OS X GUI clients like Tower