Last active
September 29, 2017 18:36
-
-
Save jcbf/e3c4c4a0c03a2e27ba0743e10782d980 to your computer and use it in GitHub Desktop.
Post commit host to update JIRA from SVN
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/sh | |
# Author: Jose Ferreira based on Carlo Sciolla <[email protected]> script | |
# Revision: 0.1 | |
USER="username" | |
PASS="xxxxxxxxx" | |
JIRA="https://blabla.atlassian.net" | |
REPO=$1 | |
REV=$2 | |
USERNAME=$3 | |
# Only for a specific repo | |
[ "x$REPO" == "xMPSv3" ] || exit | |
LOG=`svnlook log -r$REV $REPO` | |
#read LOG | |
function parse_trac_ids() { | |
for ID in "$(echo $LOG | grep -Eo '#[0-9]{4,5}')" | |
do | |
echo $ID | sed -e 's/#//' | |
done | |
} | |
function parse_jira_ids() { | |
for ID in "$(echo $LOG | grep -Eo '[A-Z]+-[0-9]+')" | |
do | |
echo $ID | |
done | |
} | |
# Search for Jira tickets XXXX-nnnnn | |
JIRA_IDS=$(parse_jira_ids) | |
for JIRA_ID in $JIRA_IDS | |
do | |
[ "x$DEBUG" == "x" ] || echo "ID : $JIRA_ID" | |
JSON_DATA=$(cat <<EOF | |
{ | |
"relationship" : "Related commits", | |
"object" : { | |
"url" : "https://trac.example.net/projects/$REPO/changeset/$REV", | |
"title" : "$USERNAME commited r$REV", | |
"summary" : "$LOG" | |
} | |
} | |
EOF | |
) | |
JIRA_URL="$JIRA/rest/api/latest/issue/$JIRA_ID/remotelink" | |
[ "x$DEBUG" == "x" ] || echo curl -v -u "$USER:$PASS" -X POST -H "Content-type: application/json" -d"$JSON_DATA" $JIRA_URL | |
curl -Ns -v -u $USER:$PASS -X POST -H "Content-type: application/json" -d"$JSON_DATA" $JIRA_URL > /tmp/post-commit-jira.log 2>&1 | |
# Search for Trac tickets #nnnn | |
TRAC_IDS=$(parse_trac_ids) | |
for TRAC_ID in $TRAC_IDS | |
do | |
JSON_DATA=$(cat <<EOF | |
{ | |
"relationship" : "Trac tickets", | |
"object" : { | |
"url" : "https://trac.example.net/projects/$REPO/ticket/$TRAC_ID", | |
"title" : "#$TRAC_ID", | |
"summary" : "" | |
} | |
} | |
EOF | |
) | |
JIRA_URL="$JIRA/rest/api/latest/issue/$JIRA_ID/remotelink" | |
[ "x$DEBUG" == "x" ] || echo curl -v -u "$USER:$PASS" -X POST -H "Content-type: application/json" -d"$JSON_DATA" $JIRA_URL | |
curl -Ns -v -u $USER:$PASS -X POST -H "Content-type: application/json" -d"$JSON_DATA" $JIRA_URL > /tmp/post-commit-jira.log 2>&1 | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment