Created
August 26, 2013 15:20
-
-
Save alandotcom/6342617 to your computer and use it in GitHub Desktop.
A commit-msg shell function to insert hyper-links to JIRA issues directly into the commits that are related. We use Gerrit for code-review, so this also takes into account that a changeID may exist in the commit message. Adding the link is simply a matter of putting the JIRA issue tag in the commit message header surrounded by brackets. Multiple…
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/bash | |
| MSG="$1" | |
| # Add JIRA hyperlinks to the end of the commmit message | |
| # Using ggrep (gnu grep) and | |
| add_JiraUrl() { | |
| # Get all the JIRA numbers from the commit heading e.g., [AIP-2024][APPS-2000] | |
| JIRA=$(cat $MSG | head -n 1 | ggrep -Po '(?<=\[)[A-Z]*[\-]\d*(?=\])') | |
| # Customize URL to your JIRA | |
| URL="https://climate.jira.com/browse" | |
| # We use Gerrit so find the changeId if it exists | |
| changeIdLine=$(grep -n 'Change-Id' $MSG | cut -d : -f 1) | |
| # Append the URL(s) to the commit msg | |
| for issue in $(echo $JIRA) | |
| do | |
| issueUrl="$URL/$issue" | |
| # Skip URLs that have been added | |
| if grep $issueUrl $MSG >/dev/null | |
| then | |
| continue | |
| fi | |
| # Append before Change-Id if it exists | |
| if [[ $changeIdLine ]] | |
| then | |
| # append URL before change ID | |
| let lineBefore=changeIdLine-2 | |
| gsed "$lineBefore a $issueUrl" $MSG > $msg.tmp | |
| mv $msg.tmp $MSG | |
| let changeIdLine+=1 | |
| continue | |
| fi | |
| # Append URL to the end otherwise | |
| echo $issueUrl >> $MSG | |
| done | |
| } | |
| add_JiraUrl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment