-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
51 lines (43 loc) · 1.73 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
const core = require('@actions/core');
const github = require('@actions/github');
const jq = require('jq-web');
const fs = require('fs');
const path = require('path');
try {
const filterPush = core.getInput('filter_push');
const filterPullRequest = core.getInput('filter_pull_request');
const filterPrefix = core.getInput('filter_prefix');
const shouldDump = core.getInput('dump');
const dumpPath = core.getInput('dump_path');
const shouldPrint = core.getInput('print');
const isPullRequest = github.context.payload.pull_request !== undefined;
const branch = isPullRequest ? github.context.payload.pull_request.head.ref : path.basename(github.context.payload.ref);
const filter = filterPrefix + (isPullRequest ? filterPullRequest : filterPush);
core.setOutput('pull_request', JSON.stringify(isPullRequest));
core.setOutput('branch', branch);
console.log(`Filter: ${filter}`);
jq.promised.json(github.context.payload, filter)
.then((output) => {
core.setOutput('value', JSON.stringify(output));
})
.catch((err) => {
core.setFailed(err);
});
// Get the JSON webhook payload for the event that triggered the workflow
const payload = JSON.stringify(github.context.payload, undefined, 2);
if(shouldPrint) {
core.startGroup('Payload');
console.log(payload);
core.endGroup()
}
if(shouldDump) {
fs.writeFile(dumpPath, payload, function(err) {
if(err) {
core.setFailed(err);
}
console.log(`Payload dump file saved at "${dumpPath}".`);
});
}
} catch (error) {
core.setFailed(error.message);
}