-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.js
56 lines (47 loc) · 1.46 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
export * from "probot";
import { createProbot } from "probot";
import pino from "pino";
import { readFileSync } from "node:fs";
import { transport } from "./pino-transport-github-actions.js";
export async function run(app) {
const log = pino({}, transport);
const githubToken =
process.env.GITHUB_TOKEN ||
process.env.INPUT_GITHUB_TOKEN ||
process.env.INPUT_TOKEN;
if (!githubToken) {
log.error(
"[probot/adapter-github-actions] a token must be passed as `env.GITHUB_TOKEN` or `with.GITHUB_TOKEN` or `with.token`, see https://github.com/probot/adapter-github-actions#usage"
);
return;
}
const envVariablesMissing = [
"GITHUB_RUN_ID",
"GITHUB_EVENT_NAME",
"GITHUB_EVENT_PATH",
].filter((name) => !process.env[name]);
if (envVariablesMissing.length) {
log.error(
`[probot/adapter-github-actions] GitHub Action default environment variables missing: ${envVariablesMissing.join(
", "
)}. See https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables`
);
return;
}
const probot = createProbot({
overrides: {
githubToken,
log,
},
});
await probot.load(app);
return probot
.receive({
id: process.env.GITHUB_RUN_ID,
name: process.env.GITHUB_EVENT_NAME,
payload: JSON.parse(readFileSync(process.env.GITHUB_EVENT_PATH)),
})
.catch((error) => {
probot.log.error(error);
});
}