Skip to content

Commit

Permalink
fixup! Try without error wrapping to see if error message is clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
tibdex committed Sep 9, 2023
1 parent 495b461 commit eff9aff
Showing 1 changed file with 44 additions and 50 deletions.
94 changes: 44 additions & 50 deletions src/index.ts
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!");

0 comments on commit eff9aff

Please sign in to comment.