-
Notifications
You must be signed in to change notification settings - Fork 6
/
git-jirabranch
executable file
·67 lines (46 loc) · 2.04 KB
/
git-jirabranch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash -e
USAGE='<branchname>'
LONG_USAGE='git-jirabranch lets you create a new branch based on a
JIRA issue and mark the issue as in progress.'
. git-sh-setup
CACHE_FILE=$GIT_DIR/jira.cache
JIRA_SERVER=$(git config jira.server || true)
JIRA_USER=$(git config jira.user || true)
JIRA_PASSWORD=$(git config jira.password || true)
JIRA_CLI=$(git config jira.cli || true)
GIT_USER=$(git config user.name || echo $USER)
JIRA_CMD="$JIRA_CLI --server $JIRA_SERVER --user $JIRA_USER --password $JIRA_PASSWORD"
function get_cached_issue () {
local ISSUE=$1
test -f $CACHE_FILE || return 0
local LINE=`grep ^$ISSUE: $CACHE_FILE`
test -n "$LINE" || return 0
ISSUE_DESCR=$(echo $LINE | sed -e "s/^$ISSUE: //")
}
function fail () {
echo $@
exit 1
}
# start to work
require_work_tree
BRANCH_NAME=$1
test -n "$BRANCH_NAME" || usage
test -n "$GIT_DIR" || fail "Missing GIT_DIR variable"
test -n "$JIRA_SERVER" || fail "Missing git config variable jira.server (set it with 'git config jira.server ...')"
test -n "$JIRA_CLI" || fail "Missing git config variable jira.cli (set it with 'git config jira.cli ...')"
test -n "$JIRA_USER" || fail "Missing git config variable jira.user (set it with 'git config jira.user ...')"
test -n "$JIRA_PASSWORD" || fail "Missing git config variable jira.password (set it with 'git config jira.password ...')"
[[ $BRANCH_NAME =~ ^[A-Z]+-[0-9]+$ ]] || fail "Branch $BRANCH_NAME does not appear to be a JIRA issue"
echo "Doing a branch for $BRANCH_NAME"
$JIRA_CMD --action updateIssue --issue $BRANCH_NAME --assignee $JIRA_USER
$JIRA_CMD --action progressIssue --issue $BRANCH_NAME --step "Start Progress"
$JIRA_CMD --action addComment --issue $BRANCH_NAME --comment "Coding started by $GIT_USER"
# Cache the jira issue title for later cheaper commits
get_cached_issue $BRANCH_NAME
if test -z "$ISSUE_DESCR"
then
ISSUE_DESCR=`$JIRA_CMD --action getFieldValue --issue $BRANCH_NAME --field Summary | sed -e '1d'`
echo "$BRANCH_NAME: $ISSUE_DESCR" >> $CACHE_FILE
fi
git checkout -b $BRANCH_NAME
echo "*** You are now on branch $BRANCH_NAME ***"