My Git hint : a feature per commit

Have you had a look on your project git log ? It is often an enumeration of changes which are sometimes not explained correctly… « bugfixes », « some changes », « work in progress », « pull request review ».

wip git log

The log what you would want to see is a log of all features recently added from the JIRA (or any other issue tracker) board.
Moreover, having your features grouped in one commit will be a way to know all of the necessary changes for each issue (because a git diff will reveal all the changes of a feature at once)

Here is how it can be done :

– As a setup, create this command alias in your .gitconfig file (I assume that your main branch is called « master » here.)

[alias]
singleCommit = "!f() { git pull origin master --no-edit && git push && git reset --soft origin/master && git commit -m \"$1\" && git push -f; }; f"

– create a git branch from « master »
– commit everything you want inside this branch, don’t hesitate to commit or push any correction for a mistake you found.
– create a pull request if you need to, review the comments, commit / push, and so on.
– when everything is ready and the code is ready to be merged, find the JIRA code (or your issue tracker issue id) (we will name it MYPROJECT-XXXX)
– issue this command : git singleCommit "MYPROJECT-XXXX a comment for this feature" (change this text to the aim, or the title of the feature)
– if the command fails, your branch is not synced with master. Resolve the conflicts, git add . and git commit, then go back to the instruction before.
– now you can merge. There will be ONE commit for all the content of the branch.

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.

JIRA command line (jilla)

J’ai récemment intégré un outil en ligne de commande pour avoir des informations rapides sur une issue JIRA sans me rendre sur l’interface web et naviguer parmi les dashboards.

Cet outil, pratique lorsque l’on travaille dans un shell, permet de ne pas être déconcentré pendant son activité de développement.
Il s’installe en tant que package de NodeJS en utilisant la commande npm install -g jilla.

Seuls soucis : il ne passe pas les proxy, et ne s’adapte pas aux états autres que OPEN, RESOLVED, NEEDINFO, CLOSED.
Pour outrepasser ce problème, j’ai forké le repository et j’ai amélioré cette prise en charge.
J’ai également écrit une petite méthode pour obtenir en sortie console les infos du Sprint Scrum actuel sur JIRA Agile.
J’ai aussi écrit un petit script pour que l’id de l’issue actuelle soit devinée à partir de la branche de développement git sur laquelle on travaille.

Ce fork se trouve à l’adresse https://github.com/libetl/jilla/

Pour l’obtenir (que cette modif soit intégrée ou non dans la prochaine version de cet outil), il vous faut copier les fichiers gira et jilla dans votre dossier /usr/local/bin (ou /usr/bin). Puis (re)lancer la configuration via jilla config.