forked from JuriKiin/filter-json-array
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (26 loc) · 839 Bytes
/
index.js
File metadata and controls
34 lines (26 loc) · 839 Bytes
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
const core = require('@actions/core');
const github = require('@actions/github');
try {
const data = core.getInput('data').toString();
const matcher = core.getInput('matcher');
console.log(`Executing with: ${data}`);
console.log(`Comparing to matcher(s): ${matcher}`);
let filteredOutput = [];
let splitMatches = matcher.split(',');
let useMatch = core.getInput('use-match');
let addToArray = (item) => {
if (filteredOutput.includes(item)) return;
else filteredOutput.push(item);
}
JSON.parse(data.replace(/\\/g,'')).forEach(str => {
splitMatches.forEach(match => {
if (str.includes(match)) {
if (useMatch) addToArray(match);
else addToArray(str);
}
});
});
core.setOutput("array", filteredOutput);
} catch (error) {
core.setFailed(error.message);
}