-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
50 lines (45 loc) · 2.07 KB
/
main.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
import action from './lib/action.js'
import core from '@actions/core';
import github from '@actions/github';
const umamiServer = core.getInput('umami-server', { required: true }); // example : https://umami.myinstance.com
const umamiUser = core.getInput('umami-user', { required: true }); // example : admin
const umamiPassword = core.getInput('umami-password', { required: true }); // example : mY53[R3T
const umamiSiteDomain = core.getInput('umami-site-domain');// ''
const umamiReportFile = core.getInput('umami-report-file');// ''
const umamiReportContent = core.getInput('umami-report-content');// 'pageviews|events|urls'
const umamiPeriod = core.getInput('umami-period');// '24h'
const umamiUnit = core.getInput('umami-unit');// 'hour' // used by pageviews and events. need to be correlated to the period
const umamiTz = core.getInput('umami-tz');// 'Europe/Paris'
const rethrow = (err) => {throw err;};
const printContext = () => {
// Get the JSON webhook payload for the event that triggered the workflow
const payload = JSON.stringify(github.context.payload, undefined, 2)
console.log(`The event payload: ${payload}`);
};
const actionUmamiReport = async function() {
try {
if (umamiServer === null || umamiServer === undefined) {
throw new Error("please setup your environment");
}
let options = {};
options.server = umamiServer;
options.user = umamiUser;
options.password = umamiPassword;
options.domain = umamiSiteDomain;
options.outputFile = umamiReportFile;
options.reportContent = umamiReportContent;
options.period = umamiPeriod;
options.unit = umamiUnit;
options.tz = umamiTz;
await action.fetchUmamiServerApi(umamiServer);
// printContext();
const reportResult = await action.umamiReport(options).catch(rethrow);
if ('targetFile' in reportResult) {
core.info(`Generated : ${reportResult.targetFile}`);
}
} catch (error) {
console.info(`ERROR: ${error}`)
core.setFailed(error);
}
}
actionUmamiReport();