Skip to content

Instantly share code, notes, and snippets.

@skuro
Created February 18, 2013 22:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save skuro/4981464 to your computer and use it in GitHub Desktop.
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
#!/bin/sh
# SVN post-commit hook to link revisions to JIRA tickets
#
# Author: Carlo Sciolla <carlo@backbase.com>
# 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