-
Notifications
You must be signed in to change notification settings - Fork 141
/
index.ts
51 lines (42 loc) · 1.55 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
49
50
51
import { Buffer } from "node:buffer";
import { getInput, info, setFailed, setOutput, setSecret } from "@actions/core";
import ensureError from "ensure-error";
import isBase64 from "is-base64";
import { fetchInstallationToken } from "./fetch-installation-token.js";
const run = async () => {
try {
const appId = getInput("app_id", { required: true });
const installationIdInput = getInput("installation_id");
const installationId = installationIdInput
? Number(installationIdInput)
: undefined;
const permissionsInput = getInput("permissions");
const permissions = permissionsInput
? (JSON.parse(permissionsInput) as Record<string, string>)
: undefined;
const privateKeyInput = getInput("private_key", { required: true });
const privateKey = isBase64(privateKeyInput)
? Buffer.from(privateKeyInput, "base64").toString("utf8")
: privateKeyInput;
const repositoryInput = getInput("repository", { required: true });
const [owner, repo] = repositoryInput.split("/");
const githubApiUrlInput = getInput("github_api_url", { required: true });
const githubApiUrl = new URL(githubApiUrlInput);
const installationToken = await fetchInstallationToken({
appId,
githubApiUrl,
installationId,
owner,
permissions,
privateKey,
repo,
});
setSecret(installationToken);
setOutput("token", installationToken);
info("Token generated successfully!");
} catch (_error: unknown) {
const error = ensureError(_error);
setFailed(error);
}
};
void run();