-
-
Save pipwilson/87f61dfc5023e095ee27326c74956ec4 to your computer and use it in GitHub Desktop.
A post-commit svn hook to add comments to 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]> | |
# Author: Phil Wilson | |
# Revision: 0.2 | |
# fill in your Jira credentials and URL: | |
USER=foo | |
PASS=test123 | |
JIRA=https://snakeoil.atlassian.net | |
REPO=$1 | |
REV=$2 | |
LOG=`svn 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_comment(){ | |
JIRA_ID=$1 | |
JSON_DATA=$(cat <<EOF | |
{ | |
"body" : "$LOG" | |
} | |
EOF | |
) | |
JIRA_URL="$JIRA/rest/api/2/issue/$JIRA_ID/comment" | |
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 | |
echo $JIRA_ID | |
add_comment $JIRA_ID | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment