-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Try without error wrapping to see if error message is clearer
- Loading branch information
Showing
1 changed file
with
44 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,52 @@ | ||
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"; | ||
import { getInstallationRetrievalDetails } from "./installation-retrieval-details.js"; | ||
|
||
try { | ||
const appId = getInput("app_id", { required: true }); | ||
|
||
const githubApiUrlInput = getInput("github_api_url", { required: true }); | ||
const githubApiUrl = new URL(githubApiUrlInput); | ||
|
||
const installationRetrievalMode = getInput("installation_retrieval_mode", { | ||
required: true, | ||
}); | ||
const installationRetrievalPayload = getInput( | ||
"installation_retrieval_payload", | ||
{ required: true }, | ||
); | ||
const installationRetrievalDetails = getInstallationRetrievalDetails({ | ||
mode: installationRetrievalMode, | ||
payload: installationRetrievalPayload, | ||
}); | ||
|
||
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 repositoriesInput = getInput("repositories"); | ||
const repositories = repositoriesInput | ||
? (JSON.parse(repositoriesInput) as string[]) | ||
: undefined; | ||
|
||
const token = await fetchInstallationToken({ | ||
appId, | ||
githubApiUrl, | ||
installationRetrievalDetails, | ||
permissions, | ||
privateKey, | ||
repositories, | ||
}); | ||
|
||
setSecret(token); | ||
setOutput("token", token); | ||
info("Token generated successfully!"); | ||
} catch (_error: unknown) { | ||
const error = ensureError(_error); | ||
setFailed(error); | ||
} | ||
const appId = getInput("app_id", { required: true }); | ||
|
||
const githubApiUrlInput = getInput("github_api_url", { required: true }); | ||
const githubApiUrl = new URL(githubApiUrlInput); | ||
|
||
const installationRetrievalMode = getInput("installation_retrieval_mode", { | ||
required: true, | ||
}); | ||
const installationRetrievalPayload = getInput( | ||
"installation_retrieval_payload", | ||
{ required: true }, | ||
); | ||
const installationRetrievalDetails = getInstallationRetrievalDetails({ | ||
mode: installationRetrievalMode, | ||
payload: installationRetrievalPayload, | ||
}); | ||
|
||
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 repositoriesInput = getInput("repositories"); | ||
const repositories = repositoriesInput | ||
? (JSON.parse(repositoriesInput) as string[]) | ||
: undefined; | ||
|
||
const token = await fetchInstallationToken({ | ||
appId, | ||
githubApiUrl, | ||
installationRetrievalDetails, | ||
permissions, | ||
privateKey, | ||
repositories, | ||
}); | ||
|
||
setSecret(token); | ||
setOutput("token", token); | ||
info("Token generated successfully!"); |