Files
jami-daemon/tools/git-redmine
Vivien Didelot f93a5ffb24 tools: add Gerrit/Redmine utilities for Git
This commit adds two dev scripts, intended to be used with Git. They
allow easy interaction with Gerrit (using the commit change ID) and
Redmine (using the issue reference).

Usage examples:

    # Copy Gerrit change URL of HEAD, for later pasting
    git gerrit url | xclip

    # Open Gerrit in a web browser for the parent commit
    git gerrit open HEAD^

    # Fetch the last version corresponding to a commit
    git gerrit fetch 2460d16

    # Open Redmine issue related to the current commit
    git redmine open

These scripts may be used directly:

    ./tools/git-gerrit

or installed as a Git subcommand (recommended):

    git config alias.gerrit '!tools/git-gerrit'
    git config alias.redmine '!tools/git-redmine'

The configuration is managed through git config. Running these scripts
with missing configuration (e.g. host, port) will prompt the setup.

Note on global usage: optionally, you can specify the global path of
these scripts, or add them to your $PATH, in order to use them in any
repo, and eventually have global settings, like:

    git config --global redmine.url https://...

Change-Id: Ie8530fd03e00452075ab045b278923d03d0ead20
2014-05-16 14:02:30 -04:00

59 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
#
# Copyright 2014 Savoir-Faire Linux Inc.
# Author: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
# Licensed under the terms of the GNU GPL v3, or at your option, any later version.
#
# You can install this script as a Git subcommand with one of the 2 methods below:
#
# 1) git config alias.redmine '!tools/git-redmine'
# 2) or put this script in your $PATH
usage () {
echo "Usage:"
echo " $0 <url|open> [<git-rev>]"
echo " $0 help"
echo
echo "Examples:"
echo " git redmine open # open the Redmine ticket related to the current commit"
echo " git redmine url HEAD~2"
}
test $# -ge 1 -a $# -le 2 || {
echo "Invalid syntax."
usage
exit 1
}
test "$1" = "help" && {
usage
exit
}
REDMINE_URL=`git config redmine.url`
test -n "$REDMINE_URL" || {
echo "You must configure your Redmine URL, e.g.:"
echo
echo " git config redmine.url https://projects.savoirfairelinux.com"
echo
exit 1
}
ISSUE=`git show --summary --format=%b $2 | perl -n -e '/^(Refs|Issue:) #(\d+)$/ && print $2'`
test -n "$ISSUE" || {
echo "no issue ID!"
exit 1
}
URL=$REDMINE_URL/issues/$ISSUE
case $1 in
url) echo $URL ;;
open) xdg-open $URL ;;
*) echo "Oops, bad command" ; usage ; exit 1 ;;
esac
exit