-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitbugzilla.sh
More file actions
executable file
·86 lines (71 loc) · 1.77 KB
/
gitbugzilla.sh
File metadata and controls
executable file
·86 lines (71 loc) · 1.77 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
# Settings
FILE=/tmp/bugs.txt
BRANCHES=($(git branch))
BUGPREFIX="bug"
BUGZILLA="bugzilla"
VERSION="1.1"
function change_descriptions() {
while read -a fields; do
local bug_no=${fields[0]#?}
local status=${fields[1]}
local author=${fields[3]}
for i in {0..4}; do
unset fields[$i]
done
local description=${fields[@]}
description="${description//\"/\\\"}"
local branch_name="$BUGPREFIX$bug_no"
local found_branch=( ${BRANCHES[@]/$branch_name} )
if ! [ ${#found_branch[@]} == ${#BRANCHES[@]} ]; then
x="git config --replace-all branch.${branch_name}.description \"$status $description\""
eval $x
fi
done < $FILE
}
# Shows branches with descriptions
function show_descriptions() {
branches=$(git for-each-ref --format='%(refname)' refs/heads/ | sed 's|refs/heads/||')
for branch in $branches; do
desc=$(git config branch.$branch.description)
if [ $branch == $(git rev-parse --abbrev-ref HEAD) ]; then
branch="* \033[0;32m$branch\033[0m"
else
branch=" $branch"
fi
echo "$branch \033[0;36m$desc\033[0m"
done
}
function generate_text_file() {
$BUGZILLA --bugzilla=$BUGZILLA_URL --user="$BUGZILLA_USERNAME" --password="$BUGZILLA_PASSWORD" query > $FILE
change_descriptions
}
function remove_temp_file() {
rm $FILE
}
function show_help() {
echo "gitbugzilla, version $VERSION
usage: gitbugzilla <COMMAND>
-s Show git branches with their descriptions
-g Populate git branches with Bugzilla's information"
}
options_found=0
while getopts sg opt; do
options_found=1
case $opt in
s)
show_descriptions
;;
g)
generate_text_file
change_descriptions
remove_temp_file
;;
*)
show_help
;;
esac
done
if ((!options_found)); then
show_help
fi