-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.js
executable file
·72 lines (58 loc) · 1.93 KB
/
action.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
const core = require('@actions/core');
const Arn = require('./arn');
const Jira = require('./jira');
const jira = new Jira({
baseUrl: process.env.JIRA_BASEURL,
email: process.env.JIRA_EMAIL,
token: process.env.JIRA_TOKEN,
});
//Anne's ARN webhook url
const webhookUrl = 'https://arn.upraise.io/arn/executewebhook/44998/fd803c08-6778-43bb-a5fc-66a3768447ac';
const arn = new Arn({webhookUrl});
// 1. update JIRA issues
// 2. send a webhook to the ARN (Automated release notes) - JIRA app -
// with the componentName-tagName label
async function exec ({ issueIds, componentName, tagName, releaseDate }) {
try {
console.log({ issueIds, componentName, tagName, releaseDate });
if (issueIds.length === 0) {
console.log('No Jira issues given, do nothing');
return
}
const errors = await jira.updateIssues({
issueIds,
componentName,
tagName,
releaseDate,
});
if (errors.length === 0) {
console.log(`Updated successfully update following Jira issues: ${issueIds}`);
} else {
console.log(`Failed to update some Jira tickets: ${errors}`);
}
await arn.callWebhook( `${componentName}-${tagName}` );
} catch (error) {
console.error(error);
process.exit(1)
}
}
function parseArgs() {
return {
issueIds: filterIssueIds(core.getInput('issueIds')),
componentName: core.getInput('componentName'),
tagName: core.getInput('tagName') || process.env.TAGNAME,
releaseDate: core.getInput('releaseDate') ? new Date(core.getInput('releaseDate')) : new Date(),
notifyUsers: core.getInput('notifyUsers') === 'true',
}
}
function filterIssueIds(issueIdsStr) {
const filtered = issueIdsStr
.split(',')
.map((issueId) => issueId.trim())
.map((issueId) => issueId.replace(/"/g, ''))
.filter((issueId) => issueId !== '' &&
!issueId.includes('-00'));
filtered.sort();
return filtered
}
module.exports = { exec, parseArgs, filterIssueIds };