Created
April 28, 2014 20:13
-
-
Save blazindrop/11382735 to your computer and use it in GitHub Desktop.
What this script does is query your current git repository (in your working directory) for the provided git log range to try and parse ticket numbers of the format #<number>. It then takes those ticket numbers and queries Redmine's API to output ticket information.
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/bash | |
### What this script does is query your current git repository (in your working directory) for the provided | |
### git log range to try and parse ticket numbers of the format #<number>. It then takes those ticket numbers | |
### and queries Redmine's API to output ticket information. | |
### I have used this for release management to get a basic idea of the state of changes at any given time and | |
### also to follow-up on any items needing attention. This is a bit fragile if your Redmine body/subject has HTML in it | |
### because that makes xmllint barf on unencoded html. | |
REDMINE_URL=<Redmine URL> | |
API_KEY=<your redmine API key> | |
USE_SSL=yes | |
if [ "$USE_SSL" -eq "yes" ]; then | |
PROTO=https | |
else | |
PROTO=http | |
fi | |
if [ "$#" -lt 1 ]; then | |
echo "need a git range string. e.g. master..prod" | |
exit | |
fi | |
FULL=0 | |
IDS=0 | |
args=`getopt -l csv,full,ids '' $*` | |
for i in $args; do | |
case $i in | |
--csv) | |
ODELIM=',' | |
shift | |
;; | |
--full) | |
FULL=1 | |
shift | |
;; | |
--ids) | |
IDS=1 | |
shift | |
;; | |
esac | |
done | |
revstr=$1 | |
tickets=`git log $revstr --pretty=format:%s --no-merges | grep -P -e '#?\d{4}' | perl -ne '($ticket) = $_ =~ /(?:\s?refs\s?)?\s?#?(\d{4,}) .*/; print $ticket . "\n";' | sort | sed '/^$/d' | uniq` | |
ORS="\n" | |
if [ ! -z "$ODELIM" ]; then | |
printf "Ticket #,Sprint,Title,Author,Assignee,Status\n" | |
else | |
printf "%-10s%-30s%-50s%-20s%-20s%40s\n" "Ticket #" "Sprint" "Title" "Author" "Assignee" "Status" | |
fi | |
for ticket in $tickets; do | |
if [ "$IDS" -eq 1 ]; then | |
echo $ticket; | |
continue | |
fi | |
ticket_xml=`curl -s -H "Content-type: text/xml" -H "X-Redmine-API-Key: ${API_KEY}" ${PROTO}://${REDMINE_URL}/issues/${ticket}.xml` | |
status=`echo $ticket_xml | xmllint -format - | perl -ne 'my ($subject) = $_ =~ /<status.*name="(.*)".*>/; print $subject'` | |
if [ "$FULL" -eq 1 ]; then | |
title=`echo $ticket_xml | xmllint -format - | grep -oP -e '(?<=<subject>)(.*)(?=</subject>)'` | |
else | |
title=`echo $ticket_xml | xmllint -format - | grep -oP -e '(?<=<subject>)(.*)(?=</subject>)' | head -c 45` | |
fi | |
author=`echo $ticket_xml | xmllint -format - | perl -ne 'my ($auth) = $_ =~ /<author .*name="(.*)".*>/; print $auth'` | |
assignee=`echo $ticket_xml | xmllint -format - | perl -ne 'my ($assignee) = $_ =~ /<assigned_to .*name="(.*)".*>/; print $assignee'` | |
version=`echo $ticket_xml | xmllint -format - | perl -ne 'my ($vers) = $_ =~ /<fixed_version .*name="(.*)".*>/; print $vers'` | |
if [ ! -z "$ODELIM" ]; then | |
echo -e -n ${ticket} | |
echo -e -n $ODELIM | |
echo -e -n ${version} | |
echo -e -n $ODELIM | |
echo -e -n ${title} | |
echo -e -n $ODELIM | |
echo -e -n ${author} | |
echo -e -n $ODELIM | |
echo -e -n ${assignee} | |
echo -e -n $ODELIM | |
echo ${status} | |
else | |
printf "%-10s%-30s%-50s%-20s%-20s%40s\n" $ticket "$version" "$title" "$author" "$assignee" "$status" | |
fi | |
done | |
escape() { | |
val=`perl -MURI::Escape -e "print uri_escape(\"$1\");"` | |
echo $val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment