-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.js
60 lines (49 loc) · 1.59 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
const { inspect } = require("util");
const yaml = require("js-yaml");
const core = require("@actions/core");
const { Octokit } = require("@octokit/action");
main();
async function main() {
try {
``;
const octokit = new Octokit();
const { query, ...variables } = getAllInputs();
core.info(query);
for (const [name, value] of Object.entries(variables)) {
core.info(`> ${name}: ${value}`);
}
const time = Date.now();
const data = await octokit.graphql(query, variables);
core.info(`< 200 ${Date.now() - time}ms`);
core.setOutput("data", JSON.stringify(data, null, 2));
} catch (error) {
core.debug(inspect(error));
core.setFailed(error.message);
}
}
function getAllInputs() {
return Object.entries(process.env).reduce((result, [key, value]) => {
if (!/^INPUT_/.test(key)) return result;
const inputName =
key.toLowerCase() === "input_mediatype"
? "mediaType"
: key.substr("INPUT_".length).toLowerCase();
// The js-yaml parser cannot handle the syntax of a multi-line GraphQL query very well,
// so we just leave it as-is.
// https://github.com/octokit/graphql-action/issues/21
if (inputName === `query`) {
result.query = value;
return result;
}
if (inputName === `variables`) {
const variables = yaml.load(value);
return { ...result, ...variables };
}
result[inputName] = yaml.load(value);
result[inputName] =
result[inputName] == parseInt(result[inputName], 10)
? parseInt(result[inputName], 10)
: result[inputName];
return result;
}, {});
}