-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
48 lines (41 loc) · 1.13 KB
/
index.ts
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
import { context, getOctokit } from "@actions/github";
import { defaults as defaultGitHubOptions } from "@actions/github/lib/utils";
import { requestLog } from "@octokit/plugin-request-log";
import * as core from "@actions/core";
import fs from "fs";
import fetch from "node-fetch";
process.on("unhandledRejection", handleError);
main().catch(handleError);
async function main(): Promise<void> {
const token = process.env.GITHUB_ACCESS_TOKEN as string;
const script = process.env.SCRIPT as string;
const github = getOctokit(
token,
{
...defaultGitHubOptions,
retry: { enabled: false },
request: { ...defaultGitHubOptions.request, timeout: 10000 },
},
requestLog
);
const result = await github.rest.repos.getContent({
mediaType: {
format: "raw",
},
owner: context.repo.owner,
repo: context.repo.repo,
path: script,
});
// @ts-ignore
fs.writeFileSync("./bot.ts", result.data);
await require("./bot.ts").default({
github,
context,
core,
fetch,
});
}
function handleError(err: any): void {
console.error(err);
core.setFailed(`Unhandled error: ${err}`);
}