This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.js
67 lines (57 loc) · 1.93 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const core = require("@actions/core");
const { ServiceError, DisplayTypeError } = require("./lib/customErrors");
const LookingGlass = require("./lib/lookingGlass");
async function run() {
try {
const feedBack = core.getInput("feedback");
if (!feedBack) {
core.setFailed(
"No feedback payload was provided by a previous action, please view the documentation for using the Looking Glass at https://github.com/githubtraining/looking-glass-action"
);
}
const lookingGlass = new LookingGlass(JSON.parse(feedBack));
const reports = lookingGlass.validatePayloadSignature();
if (reports.length < 1) {
core.setFailed(
"No reports were found in the feedback payload, please view the documentation for using the Looking Glass at https://github.com/githubtraining/looking-glass-action"
);
}
for (const report of reports) {
switch (report.display_type) {
case "issues":
const {
payload,
res,
} = await lookingGlass.provideFeedbackUsingIssues(report);
console.log(res);
if (res.status !== 201) {
throw new ServiceError(res);
}
break;
case "actions":
const err = lookingGlass.provideFeedbackUsingActions(report);
if (err !== undefined) {
throw err;
}
break;
default:
throw new DisplayTypeError();
}
}
} catch (error) {
// use actions to throw author errors in actions.debug
// log to learner with core.log that error happened and isn't on them
if (
error.name === "SchemaError" ||
error.name === "ValueError" ||
error.name === "ServiceError" ||
error.name === "DisplayTypeError"
) {
core.debug(JSON.stringify({ name: error.name, message: error.message }));
core.setFailed(error.userMessage);
return;
}
core.setFailed(error);
}
}
run();