forked from patrixr/jira-release-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (63 loc) · 1.93 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
process.env.DEBUG = process.env.DEBUG || '*,-follow-redirects';
const core = require('@actions/core');
const github = require('@actions/github');
const { execute } = require('@goodcity/release-notes');
/**
* @typedef GenerationOptions
* @type {object}
* @property {boolean} [pdf]
* @property {boolean} [clipboard]
* @property {boolean} [unshallow]
* @property {string} [head]
* @property {string} [base]
* @property {string} [emailTo]
* @property {string} [emailSubject]
* @property {string} [appName]
* @property {string} [jiraCode]
* @property {string} [jiraHost]
* @property {string} [jiraUsername]
* @property {string} [jiraPassword]
* @property {string} [sendgridApiKey]
*/
function readString(key) {
return core.getInput(key);
}
function readBoolean(key) {
const val = readString(key);
return val === true || val === 'true';
}
/** @type {GenerationOptions} */
const options = {
head: readString('head'),
base: readString('base'),
jiraCode: readString('jira-code'),
jiraHost: readString('jira-host'),
jiraUsername: readString('jira-username'),
jiraPassword: readString('jira-password'),
unshallow: readBoolean('unshallow'),
pdf: readBoolean('pdf'),
emailTo: readString('email-to'),
emailSubject: readString('email-subject'),
sendgridApiKey: readString('sendgrid-api-key'),
appName: readString('app-name')
};
async function runAction() {
try {
const result = await execute(options);
if (options.pdf) {
core.setOutput("pdf", result.pdf);
console.log("Generated pdf " + pdf);
} else {
core.setOutput("markdown", result.markdown);
console.log("Generated markdown: " + result.markdown);
}
} catch (e) {
const message = e && e.message || 'Something went wrong';
core.setFailed(message);
}
}
if (options.emailTo && !options.sendgridApiKey) {
core.setFailed('The sendgrid-api-key option is required for sending emails');
} else {
runAction();
}