-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbash_jira
135 lines (108 loc) · 3.12 KB
/
bash_jira
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
# Most of the below utilites depends on the "jq" tool for parsing the
# See https://stedolan.github.io/jq/ for installing jq tool.
# JSON reponse from JIRA rest API. Below environment variables need to
# be configured for the tool to function.
# JIRA_USR - Email id of the JIRA account
# JIRA_PSW - JIRA password (or) api token for the user account
# JIRA_URL - JIRA enterprise cloud URL
# Helper method to get the JIRA issue title for given issue id.
jira_get_issue_title() {
if [[ $# -ne 1 ]]; then
echo "Usage: jira_get_issue_title <issue-id>"
return
fi
jira_get_issue_property -i $1 -p issue_title
}
jira_get_parent_issue_key() {
if [[ $# -ne 1 ]]; then
echo "Usage: jira_get_parent_issue_key <issue-id>"
return
fi
jira_get_issue_property -i $1 -p parent_key
}
jira_get_issue_assignee() {
if [[ $# -ne 1 ]]; then
echo "Usage: jira_get_issue_assignee <issue-id>"
return
fi
jira_get_issue_property -i $1 -p issue_assignee
}
jira_get_siblings() {
if [[ $# -ne 1 ]]; then
echo "Usage: jira_get_siblings <issue-id>"
return
fi
local parent_issue
parent_issue=`jira_get_parent_issue_key $1`
if ! [[ -z $parent_issue || $parent_issue == null ]]; then
jira_get_issue_property -i $parent_issue -p siblings
fi
}
jira_get_issue_type() {
if [[ $# -ne 1 ]]; then
echo "Usage: jira_get_issue_type <issue-id>"
return
fi
jira_get_issue_property -i $1 -p issue_type
}
jira_get_outward_linked_issue() {
if [[ $# -ne 1 ]]; then
echo "Usage: jira_get_outward_linked_issue <issue-id>"
return
fi
jira_get_issue_property -i $1 -p linked_issue
}
jira_filter_issue_key() {
if [[ $# -ne 1 ]]; then
echo "Usage: jira_filter_issue_key <issue-id>"
return
fi
echo "$1" | sed 's/[^a-zA-Z0-9]/-/g' | tr -s '-' | cut -d- -f1-2
}
jira_get_issue_property() {
local issue_id issue_json property c OPTIND OPTARG
while getopts 'i:j:p:h' c
do
case $c in
i) issue_id=$OPTARG ;;
j) issue_json="$OPTARG" ;;
p) property="$OPTARG" ;;
h) echo "Usage: jira_get_issue_property -p property [ -i issue_id ] [ -j issue_json ]"; return
esac
done
if [[ -z "$issue_id" && -z "$issue_json" ]] || [[ -z "$property" ]]; then
jira_get_issue_property -h
return
fi
if ! [[ -z "$issue_id" ]]; then
issue_json=`jira_get_issue_json $issue_id`
fi
_jira_get_issue_property_from_json "$issue_json" "$property"
}
jira_get_issue_json() {
local issue_key
issue_key=`jira_filter_issue_key "$1"`
curl -s --user "$JIRA_USR:$JIRA_PSW" "$JIRA_URL/rest/api/3/issue/$issue_key"
}
_jira_get_issue_property_from_json() {
local issue_json property
issue_json="$1"
property="$2"
case $property in
issue_type)
echo "$issue_json" | jq -r '.fields.issuetype.name' ;;
linked_issue)
echo "$issue_json" | jq -r '.fields.issuelinks[0].outwardIssue.key' ;;
parent_key)
echo "$issue_json" | jq -r '.fields.parent.key' ;;
issue_title)
echo "$issue_json" | jq -r '.fields.summary' ;;
issue_assignee)
echo "$issue_json" | jq -r '.fields.assignee.accountId' ;;
siblings)
echo "$issue_json" | jq -r '.fields.subtasks[] | .key + " " + .fields.summary' ;;
*)
echo "Error: $property is not implemented" ;;
esac
}