-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsprints.gs
189 lines (177 loc) · 5.98 KB
/
sprints.gs
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
* JIRA REST API Query - grab basic total responses for a JQL Query
* https://github.com/chrisurban/jira-sprint-reporting
*
* Set up some basic parameters we need for connecting with JIRA REST API
* Fill in your account email, password,
* and the URL where your project resides - cloud or server - where you log in
*
* TO DO: find another endpoint for total query only. This seems expensive
* to query for just one number.
*/
var jirauser = "[email protected]";
var jiraauth = "userpassword";
var jiraurl = "project.atlassian.net";
// alternatively, replace Utilities.base64Encode( jirauser + ":" + jiraauth ) with jirabase
// and update references below
// var jirabase = base64-encoded-string-here
/*
* USAGE
*
* add this script to your Google sheet,
* add your values above
* and call this function below,
* making sure to pass the actual JQL, and the sprint it is limited to
*
* A good way to set up your sheet, is to have Sprint names, IDs and/or versions
* in left-most columns, then reference those with your specific queries
* in right-hand cells
*
* Examples:
* =getepic(CONCATENATE("project = ",$A3," AND labels = ",$B$1))
* where column A has your project ID, and cell B1 has a specific label to search for
*
* =gettotaltime(CONCATENATE("project = ",$A3," AND ""Epic Link"" = ",$B3))/3600
* where column A has your project ID, and the next cell as an Epic key, will iterate
* through all tickets in that epic and return total time logged.
*
* Using variations of these queries will allow you to build some stats that you
* can do further math with, like percentage of reopened/total stories, etc.
*
*/
function issueCount(query) {
var parameters = {
method : "get",
accept : "application/json",
headers: {"Authorization" : "Basic " + jirabase}
};
var jira_url = "https://" + jiraurl + "/rest/api/2/search?jql=" + encodeURIComponent(query) ;
var text = UrlFetchApp.fetch(jira_url, parameters).getContentText();
var data = JSON.parse(text);
return data.total;
}
function getepic(query) {
var parameters = {
method : "get",
accept : "application/json",
headers: {"Authorization" : "Basic " + Utilities.base64Encode( jirauser + ":" + jiraauth )}
};
var jira_url = "https://" + jiraurl + "/rest/api/2/search?jql=" + encodeURIComponent(query) ;
var text = UrlFetchApp.fetch(jira_url, parameters).getContentText();
var data = JSON.parse(text);
//var issue = JSON.parse(data);
return data.issues[0].key;
}
function gettotaltime(query) {
var parameters = {
method : "get",
accept : "application/json",
headers: {"Authorization" : "Basic " + Utilities.base64Encode( jirauser + ":" + jiraauth )}
};
var jira_url = "https://" + jiraurl + "/rest/api/2/search?jql=" + encodeURIComponent(query) ;
var text = UrlFetchApp.fetch(jira_url, parameters).getContentText();
var data = JSON.parse(text);
var sum = 0;
for (x in data.issues) {
sum += data.issues[x].fields.timespent;
}
return sum;
}
/*
* ticketDetails
*
* The idea here is to use the key (ABC-123) and retrieve specific ticket values
* by way of =ticketDetails("ABC-123","status") in a formula cell
* this makes custom reporting for a list of tickets easy
* allowing you to share a Google Sheet in lieu of JIRA access
*
* customize the switch parameters to match your custom fields
*
*/
function ticketDetails(ticket,attribute) {
var parameters = {
method : "get",
accept : "application/json",
headers: {"Authorization" : "Basic " + Utilities.base64Encode( jirauser + ":" + jiraauth )}
};
if (ticket.indexOf(',') > -1) {
var arr = ticket.split(",");
var ticket = arr.splice(0,1).join("");
}
var jira_url = "https://" + jiraurl + "/rest/api/2/issue/" + encodeURIComponent(ticket) ;
var text = UrlFetchApp.fetch(jira_url, parameters).getContentText();
var data = JSON.parse(text);
switch (attribute) {
case "status":
return data.fields.status.name;
break;
case "summary":
return data.fields.summary;
break;
case "userstory":
return data.fields.customfield_10202;
//
// this field's name and customfield id will be different for your instance
//
break;
case "description":
return data.fields.description;
break;
case "priority":
return data.fields.priority.name;
break;
case "resolution":
return data.fields.resolution.name;
break;
case "assignee":
return data.fields.assignee.name;
break;
case "storypoints":
return data.fields.customfield_10004;
//
// this field's name and customfield id will be different for your instance
//
break;
default:
return "No attribute provided.";
}
// data.fields.customfield_10106 = User Story
// data.fields.description = Description
// customfield_11400 = Implementation Details
// customfield_10201 = Testing Steps
}
/*
* ticketLabels
*
* The idea here is to use the key (ABC-123) and check for specific label values
* by way of =ticketLabels("ABC-123","MVP") in a formula cell
* which will return "yes" or "no" if the ticket is labeled with the tag "MVP"
*
*
*/
function ticketLabels(ticket,checkvalue) {
var parameters = {
method : "get",
accept : "application/json",
headers: {"Authorization" : "Basic " + Utilities.base64Encode( jirauser + ":" + jiraauth )}
};
if (ticket.indexOf(',') > -1) {
var arr = ticket.split(",");
var ticket = arr.splice(0,1).join("");
}
var jira_url = "https://" + jiraurl + "/rest/api/2/issue/" + encodeURIComponent(ticket) ;
var text = UrlFetchApp.fetch(jira_url, parameters).getContentText();
var data = JSON.parse(text);
var labelstring = data.fields.labels;
if (labelstring.indexOf(',') > -1) {
var labelarray = labelstring.split(",");
}
else {
var labelarray = labelstring;
}
if (labelarray.indexOf(checkvalue) > -1) {
return "yes";
} else {
return "no";
}
}