Created
February 18, 2013 22:44
-
-
Save skuro/4981464 to your computer and use it in GitHub Desktop.
A post-commit svn hook to expose links to Trac commits in Jira
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/sh | |
# SVN post-commit hook to link revisions to JIRA tickets | |
# | |
# Author: Carlo Sciolla <[email protected]> | |
# Revision: 0.1 | |
# fill in your Jira credentials and URL: | |
USER=foo | |
PASS=test123 | |
JIRA=https://snakeoil.atlassian.net | |
REPO=$1 | |
REV=$2 | |
LOG=`svnlook log -r$REV $REPO` | |
function parse_jira_ids(){ | |
for ID in "$(echo $LOG | grep -Po '([A-Z]*-[0-9]*)')" | |
do | |
echo $ID | |
done | |
} | |
function add_link(){ | |
JIRA_ID=$1 | |
JSON_DATA=$(cat <<EOF | |
{ | |
"relationship" : "Related commits", | |
"object" : { | |
"url" : "https://trac.snakeoil.com/project/changeset/$REV", | |
"title" : "r$REV", | |
"summary" : "$LOG" | |
} | |
} | |
EOF | |
) | |
JIRA_URL="$JIRA/rest/api/latest/issue/$JIRA_ID/remotelink" | |
curl -v -u $USER:$PASS -X POST -H "Content-type: application/json" -d"$JSON_DATA" $JIRA_URL > ~/REMOVEME/post-commit.log 2>&1 | |
} | |
JIRA_IDS=$(parse_jira_ids) | |
for JIRA_ID in $JIRA_IDS | |
do | |
add_link $JIRA_ID | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment