forked from connorsmallman/github-jira-changelog-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
324 lines (264 loc) · 10.1 KB
/
index.js
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
const core = require('@actions/core');
const github = require('@actions/github');
const _ = require('lodash');
const Entities = require('html-entities');
const ejs = require('ejs');
const Haikunator = require('haikunator');
const { SourceControl, Jira } = require('jira-changelog');
const RegExpFromString = require('regexp-from-string');
const resolve = require('path').resolve;
const config = {
jira: {
api: {
host: core.getInput('jira_host'),
email: core.getInput('jira_email'),
token: core.getInput('jira_token'),
},
baseUrl: core.getInput('jira_base_url'),
ticketIDPattern: RegExpFromString(core.getInput('jira_ticket_id_pattern')),
approvalStatus: ['Current Release Candidate', 'Ready to Deploy', "Ready for QA", "In QA", "QA Feedback", "Ready to RElease"],
excludeIssueTypes: ['Sub-task'],
includeIssueTypes: [],
releaseVersion: core.getInput('release_version'),
generateNotesOnly: core.getInput('generate_notes_only')
},
sourceControl: {
defaultRange: {
to: core.getInput("source_control_range_to"),
from: core.getInput("source_control_range_from"),
symmetric: false // if we don't make it non-symmetric, then we'll get changes in master that aren't in the release branch
},
gitHubToken: core.getInput("github_token"),
repoName: core.getInput('repo_name')
},
};
const template = `
<% if (jira.releaseVersions && jira.releaseVersions.length) { %>
Release version: <%= jira.releaseVersions[0].name -%>
<% jira.releaseVersions.forEach((release) => { %>
* <%= release.projectKey %>: <%= jira.baseUrl + '/projects/' + release.projectKey + '/versions/' + release.id -%>
<% }); -%>
<% } %>
The following Tickets are in the RT but are missing values for "RT State"
---------------------
<% tickets.noRT.forEach((ticket, index) => { %>
*<%= index+1 %>. Dev Card: [<%= ticket.key %>](<%= jira.baseUrl + '/browse/' + ticket.key %>)*
**<%= ticket.fields.summary %>**
Description: <%= ticket.fields.customfield_10047 %>
<% }); -%>
<% if (!tickets.noRT.length) {%> ~ None ~ <% } %>
RT Jira Tickets Summary
---------------------
<% tickets.allForRT.forEach((ticket, index) => { %>
*<%= index+1 %>. Dev Card: [<%= ticket.key %>](<%= jira.baseUrl + '/browse/' + ticket.key %>)*
**<%= ticket.fields.summary %>**
Description: <%= ticket.fields.customfield_10047 %>
<% }); -%>
<% if (!tickets.allForRT.length) {%> ~ None ~ <% } %>
Pending Approval
---------------------
<% tickets.pendingByOwner.forEach((owner) => { %>
<%= (owner.slackUser) ? '@'+owner.slackUser.name : owner.email %>
<% owner.tickets.forEach((ticket) => { -%>
* <%= jira.baseUrl + '/browse/' + ticket.key %> - <%= ticket.fields.status.name %>
<% }); -%>
<% }); -%>
<% if (!tickets.pendingByOwner.length) {%> ~ None. Yay! ~ <% } %>
Other Commits
---------------------
<% commits.noTickets.forEach((commit) => { %>
* <%= commit.slackUser ? '@'+commit.slackUser.name : commit.authorName %> - [<%= commit.revision.substr(0, 7) %>] - <%= commit.summary -%>
<% }); -%>
<% if (!commits.noTickets.length) {%> ~ None ~ <% } %>
`;
const qaTemplate = `
<% if (jira.releaseVersions && jira.releaseVersions.length) { %>
Release version: <%= jira.releaseVersions[0].name -%>
<% jira.releaseVersions.forEach((release) => { %>
* <%= release.projectKey %>: <%= jira.baseUrl + '/projects/' + release.projectKey + '/versions/' + release.id -%>
<% }); -%>
<% } %>
QA Tickets Summary
---------------------
<% tickets.allForQA.forEach((ticket) => { %>
* [<%= ticket.fields.issuetype.name %>] - [<%= ticket.key %>](<%= jira.baseUrl + '/browse/' + ticket.key %>) <%= ticket.fields.summary -%>\n
** QA Notes: <%=ticket.fields.customfield_10079 %>
<% }); -%>
<% if (!tickets.allForQA.length) {%> ~ None ~ <% } %>
Pending Approval
---------------------
<% tickets.pendingByOwner.forEach((owner) => { %>
<%= (owner.slackUser) ? '@'+owner.slackUser.name : owner.email %>
<% owner.tickets.forEach((ticket) => { -%>
* <%= jira.baseUrl + '/browse/' + ticket.key %> - <%= ticket.fields.status.name %>
<% }); -%>
<% }); -%>
<% if (!tickets.pendingByOwner.length) {%> ~ None. Yay! ~ <% } %>
Other Commits
---------------------
<% commits.noTickets.forEach((commit) => { %>
* <%= commit.slackUser ? '@'+commit.slackUser.name : commit.authorName %> - [<%= commit.revision.substr(0, 7) %>] - <%= commit.summary -%>
<% }); -%>
<% if (!commits.noTickets.length) {%> ~ None ~ <% } %>
`;
// identify tickets that don't have a value for "RT State"
function nonRTInformation(ticket) {
let stateFieldValue = ticket.fields.customfield_10048 || [];
if (stateFieldValue.length <= 0) {
return true;
}
return false;
}
// which issues are in the release?
function inRelease(ticket, version) {
const versionStrings = ticket.fields.fixVersions.map(v => v.name);
console.log("Checkin ticket: " + ticket.key);
console.log("Version: ", versionStrings);
const projectString = ticket.key.split("-")[0];
if ( projectString == "TIER2" ) {
return true;
}
console.log(versionStrings.includes(version));
return versionStrings.includes(version);
}
function shouldExcludeTicketFromList(ticket, isQA) {
if(ticket.fields.status.name == "Deployed" || ticket.fields.status.name == "Completed" || ticket.fields.status.name == "Done. Follow up?" || ticket.fields.status.name == "Closed" || ticket.fields.status.name == 'Needs Feature Testing' || ticket.fields.status.name == 'Ready to Enable' || ticket.fields.status.name == 'Deployed and Eanbled') {
return true;
}
if (isQA) {
return false;
}
let stateFieldValue = ticket.fields.customfield_10048 || [];
if (stateFieldValue.length == 0){
return true;
}
if (stateFieldValue.length == 1) {
return stateFieldValue[0].value == 'No RT'
}
return false;
}
function generateReleaseVersionName() {
const hasVersion = process.env.VERSION;
if (hasVersion) {
return process.env.VERSION;
} else {
const haikunator = new Haikunator();
return haikunator.haikunate();
}
}
function transformCommitLogs(config, logs) {
let approvalStatus = config.jira.approvalStatus;
if (!Array.isArray(approvalStatus)) {
approvalStatus = [approvalStatus];
}
// Tickets and their commits
const ticketHash = logs.reduce((all, log) => {
log.tickets.forEach((ticket) => {
all[ticket.key] = all[ticket.key] || ticket;
all[ticket.key].commits = all[ticket.key].commits || [];
all[ticket.key].commits.push(log);
});
return all;
}, {});
const ticketList = _.sortBy(Object.values(ticketHash), ticket => ticket.fields.issuetype.name);
let pendingTickets = ticketList.filter(ticket => !approvalStatus.includes(ticket.fields.status.name));
// Pending ticket owners and their tickets/commits
const reporters = {};
pendingTickets.forEach((ticket) => {
const email = ticket.fields.reporter.emailAddress;
if (!reporters[email]) {
reporters[email] = {
email,
name: ticket.fields.reporter.displayName,
slackUser: ticket.slackUser,
tickets: [ticket]
};
} else {
reporters[email].tickets.push(ticket);
}
});
const pendingByOwner = _.sortBy(Object.values(reporters), item => item.user);
// Output filtered data
return {
commits: {
all: logs,
tickets: logs.filter(commit => commit.tickets.length),
noTickets: logs.filter(commit => !commit.tickets.length)
},
tickets: {
pendingByOwner,
all: ticketList,
approved: ticketList.filter(ticket => approvalStatus.includes(ticket.fields.status.name)),
pending: pendingTickets
}
}
}
async function main() {
try {
// Get commits for a range
const source = new SourceControl(config);
const jira = new Jira(config);
const path = resolve('./');
console.log("Test path")
console.log(path);
const range = config.sourceControl.defaultRange;
console.log(`Getting range ${range.from}..${range.to} commit logs`);
const commitLogs = await source.getCommitLogs('./', range, config.sourceControl.gitHubToken, config.sourceControl.repoName);
console.log(commitLogs);
let release = "";
console.log("Notes: ", config.jira.generateNotesOnly);
if(config.jira.generateNotesOnly == "true") {
console.log('Not generating release version -- generate notes only mode');
} else {
console.log('Generating release version');
release = config.jira.releaseVersion;
console.log(`Release: ${release}`);
}
console.log('Generating Jira changelog from commit logs');
console.log("Release: ", release);
const changelog = await jira.generate(commitLogs, release);
console.log('Changelog entry:');
console.log(changelog);
console.log('Generating changelog message');
const data = await transformCommitLogs(config, changelog);
data.jira = {
baseUrl: config.jira.baseUrl,
releaseVersions: jira.releaseVersions,
};
if(config.jira.generateNotesOnly == "true") {
data.tickets.all = data.tickets.all.filter((ticket) => {
return inRelease(ticket, config.jira.releaseVersion);
});
}
data.tickets.noRT = data.tickets.all.filter((ticket) => {
return nonRTInformation(ticket);
});
data.tickets.allForRT = data.tickets.all.filter((ticket) => {
return !shouldExcludeTicketFromList(ticket, false);
});
data.tickets.allForQA = data.tickets.all.filter((ticket) => {
return !shouldExcludeTicketFromList(ticket, true);
});
const entitles = new Entities.AllHtmlEntities();
const changelogMessage = ejs.render(template, data);
const qaLogMessage = ejs.render(qaTemplate, data);
console.log('Changelog message entry:');
console.log(entitles.decode(changelogMessage));
console.log('QA log message entry:');
console.log(entitles.decode(qaLogMessage));
console.log('Jira tickets: ');
console.log(data.tickets.all);
data.tickets.all.forEach((ticket) => {
console.log(ticket.key);
console.log("Fix Versions");
ticket.fields.fixVersions.forEach((fixVersion) => {
console.log(fixVersion);
});
});
core.setOutput('changelog_message', changelogMessage);
core.setOutput('qanotes_message', qaLogMessage);
} catch (error) {
core.setFailed(error.message);
}
}
main();