Skip to content

Instantly share code, notes, and snippets.

@pipwilson
Forked from skuro/post-commit-jira.sh
Last active June 5, 2017 12:43
Show Gist options
  • Save pipwilson/87f61dfc5023e095ee27326c74956ec4 to your computer and use it in GitHub Desktop.
Save pipwilson/87f61dfc5023e095ee27326c74956ec4 to your computer and use it in GitHub Desktop.
A post-commit svn hook to add comments to Jira
#!/bin/sh
# SVN post-commit hook to link revisions to JIRA tickets
#
# Author: Carlo Sciolla <carlo@backbase.com>
# 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