|
1 | 1 | import { Buffer } from "node:buffer"; |
| 2 | + |
2 | 3 | import { getInput, info, setFailed, setOutput, setSecret } from "@actions/core"; |
3 | 4 | import ensureError from "ensure-error"; |
4 | 5 | import isBase64 from "is-base64"; |
| 6 | + |
5 | 7 | import { fetchInstallationToken } from "./fetch-installation-token.js"; |
6 | 8 |
|
7 | | -const run = async () => { |
8 | | - try { |
9 | | - const appId = getInput("app_id", { required: true }); |
10 | | - |
11 | | - const installationIdInput = getInput("installation_id"); |
12 | | - const installationId = installationIdInput |
13 | | - ? Number(installationIdInput) |
14 | | - : undefined; |
15 | | - |
16 | | - const permissionsInput = getInput("permissions"); |
17 | | - const permissions = permissionsInput |
18 | | - ? (JSON.parse(permissionsInput) as Record<string, string>) |
19 | | - : undefined; |
20 | | - |
21 | | - const privateKeyInput = getInput("private_key", { required: true }); |
22 | | - const privateKey = isBase64(privateKeyInput) |
23 | | - ? Buffer.from(privateKeyInput, "base64").toString("utf8") |
24 | | - : privateKeyInput; |
25 | | - |
26 | | - const repositoryInput = getInput("repository", { required: true }); |
27 | | - const [owner, repo] = repositoryInput.split("/"); |
28 | | - |
29 | | - const githubApiUrlInput = getInput("github_api_url", { required: true }); |
30 | | - const githubApiUrl = new URL(githubApiUrlInput); |
31 | | - |
32 | | - const installationToken = await fetchInstallationToken({ |
33 | | - appId, |
34 | | - githubApiUrl, |
35 | | - installationId, |
36 | | - owner, |
37 | | - permissions, |
38 | | - privateKey, |
39 | | - repo, |
40 | | - }); |
41 | | - |
42 | | - setSecret(installationToken); |
43 | | - setOutput("token", installationToken); |
44 | | - info("Token generated successfully!"); |
45 | | - } catch (_error: unknown) { |
46 | | - const error = ensureError(_error); |
47 | | - setFailed(error); |
48 | | - } |
49 | | -}; |
50 | | - |
51 | | -void run(); |
| 9 | +try { |
| 10 | + const appId = getInput("app_id", { required: true }); |
| 11 | + |
| 12 | + const installationIdInput = getInput("installation_id"); |
| 13 | + const installationId = installationIdInput |
| 14 | + ? Number(installationIdInput) |
| 15 | + : undefined; |
| 16 | + |
| 17 | + const permissionsInput = getInput("permissions"); |
| 18 | + const permissions = permissionsInput |
| 19 | + ? (JSON.parse(permissionsInput) as Record<string, string>) |
| 20 | + : undefined; |
| 21 | + |
| 22 | + const privateKeyInput = getInput("private_key", { required: true }); |
| 23 | + const privateKey = isBase64(privateKeyInput) |
| 24 | + ? Buffer.from(privateKeyInput, "base64").toString("utf8") |
| 25 | + : privateKeyInput; |
| 26 | + |
| 27 | + const repositoryInput = getInput("repository", { required: true }); |
| 28 | + const [owner, repo] = repositoryInput.split("/"); |
| 29 | + |
| 30 | + const githubApiUrlInput = getInput("github_api_url", { required: true }); |
| 31 | + const githubApiUrl = new URL(githubApiUrlInput); |
| 32 | + |
| 33 | + const installationToken = await fetchInstallationToken({ |
| 34 | + appId, |
| 35 | + githubApiUrl, |
| 36 | + installationId, |
| 37 | + owner, |
| 38 | + permissions, |
| 39 | + privateKey, |
| 40 | + repo, |
| 41 | + }); |
| 42 | + |
| 43 | + setSecret(installationToken); |
| 44 | + setOutput("token", installationToken); |
| 45 | + info("Token generated successfully!"); |
| 46 | +} catch (_error: unknown) { |
| 47 | + const error = ensureError(_error); |
| 48 | + setFailed(error); |
| 49 | +} |
0 commit comments