JIRA and git : how to get a changelog automagically

Install « jilla » (a nodejs program) onto your CI server. This is a command line jira access.
Then change the parameters below in this script.

This script applies if you work using a pull Request system and version branching (for example if there are branches called release/x.x.x)


#!/bin/bash
#change the category here
JIRA_CATEGORY="CAT"
#change your project here
JIRA_PROJECT="PROJECT"
#write your JIRA_URL here
JIRA_URL="http://www.myjira.com/"
RELEASE_PREFIX="release"
PR_MERGE_COMMENT_PREFIX="Merged in"

BUG="\033[37;41m\u25BA\033[1;37;41mbug\033[0m\033[37;41m\u25C0\033[0m"
DOC="\033[37;44m\u25BA\033[1;37;44mdoc\033[0m\033[37;44m\u25C0\033[0m"
TEST="\033[37;42m\u25BA\033[1;37;42mtest\033[0m\033[37;42m\u25C0\033[0m"
OTHER=\033[37;46m\u25BA\033[1;30;46mother\033[0m\033[37;46m\u25C0\033[0m"
STORY="\033[37;45m\u25BA\033[1;37;45mstory\033[0m\033[37;45m\u25C0\033[0m"
FEATURE="\033[37;43m\u25BA\033[1;30;43mfeature\033[0m\033[37;43m\u25C0\033[0m"
JIRADESCR="~/.jiradescr"
SEP=";"

snapshotVersion (){
MILESTONE=$(echo $1 | cut -d'.' -f1);
MAJOR=$(echo $1 | cut -d'.' -f2);
MINOR=$(echo $1 | cut -d'.' -f3);

MINOR=$(expr $MINOR + 1)
NEXTVERSION=$MILESTONE.$MAJOR.$MINOR
echo $NEXTVERSION-SNAPSHOT
}

lastMerge (){
if [ -z "$(echo $1 | grep SNAPSHOT)" ];then
echo $(git rev-list origin/$(echo "$1") --merges | head -n 1)
fi
}

applyVersion (){
echo "$1 $2"
}

listVersions (){
VERSIONS="$(git for-each-ref --sort=-committerdate --format='%(refname:short)' | grep origin/$RELEASE_PREFIX | cut -d'/' -f3 | tac)"
VERSIONS="$(echo "$VERSIONS")"
echo "$VERSIONS"
snapshotVersion $(echo "$VERSIONS" | tail -n 1)
}

shiftList (){
echo "$1" | tr '\n' '-' | cut -d'-' -f2- | sed 's/-$//' | tr '-' '\n'
}

printType (){
TYPE=$1
if [ "$TYPE" == "Bogue" ] || [ "$TYPE" == "Bug" ];then
echo -n "$BUG"
elif [ "$TYPE" == "Specification" ];then
echo -n "$DOC"
elif [ "$TYPE" == "Other task" ];then
echo -n "$OTHER"
elif [ "$TYPE" == "Acceptance Test" ];then
echo -n "$TEST"
elif [ "$TYPE" == "Récit" ] || [ "$TYPE" == "Technical Story" ];then
echo -n "$STORY"
elif [ "$TYPE" == "Implementation" ] || [ "$TYPE" == "Development" ];then
echo -n "$FEATURE"
else
echo -n "$TYPE"
fi
}

changelog () {
VERSIONS=$(listVersions)
LAST=$(echo "$VERSIONS" | head -n 1)
echo "$VERSIONS" | while read VERSION;do
if [ "$VERSION" != "$LAST" ]; then
VERSIONMERGE=$(lastMerge release/$VERSION)
LASTMERGE=$(lastMerge release/$LAST)
echo -e "\033[1;4m$VERSION :\033[0m"
TICKETS="$(git --no-pager log --oneline --decorate --color $LASTMERGE..$VERSIONMERGE | grep $PR_MERGE_COMMENT_PREFIX | grep -o "\($JIRA_CATEGORY$JIRA_PROJECT\+-[0-9]\+\)" | sort | uniq)"
if [ -z "$(echo $TICKETS)" ];then
echo "Nothing"
fi
echo "$TICKETS" | while read JIRA; do
if [ ! -z "$(echo $JIRA)" ];then
LINE="$(grep $JIRA $JIRADESCR)"
if [ ! -z "$LINE" ];then
TYPE="$(echo "$LINE" | cut -d"$SEP" -f2)"
TITLE="$(echo "$LINE" | cut -d"$SEP" -f3)"
else
DESCRIBE=$(jilla describe $JIRA)
TITLE=$(echo "$DESCRIBE" | grep "^Summary: " | head -n 1 | sed "s/^Summary: //")
TYPE=$(echo $(echo "$DESCRIBE" | grep 'Type:' | head -n 1 | cut -d':' -f2))
echo "$JIRA$SEP$TYPE$SEP$TITLE" >> $JIRADESCR
fi
printType "$TYPE"
echo -n " $TITLE "
echo -n "($JIRA_URL"
echo -n $JIRA
echo ") "
fi
done
LAST=$VERSION
fi
done
}

echo "$(changelog)"

You will get this display in a console :
changelog

You can integrate that into your webApp or e-mail it at each release date.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

*