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 4369b4b commit c2dc007
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/fetch-installation-token.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { debug } from "@actions/core";
import { getOctokit } from "@actions/github";
import { createAppAuth } from "@octokit/auth-app";
import { request } from "@octokit/request";
Expand Down Expand Up @@ -67,6 +68,8 @@ export const fetchInstallationToken = async ({
throw new Error("Could not get retrieve installation.", { cause: error });
}

debug(`Retrieved installation ID: ${installationId}.`);

try {
const {
data: { token },
Expand Down
19 changes: 14 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Buffer } from "node:buffer";

import { getInput, info, setFailed, setOutput, setSecret } from "@actions/core";
import ensureError from "ensure-error";
import {
debug,
getInput,
info,
setFailed,
setOutput,
setSecret,
} from "@actions/core";
import isBase64 from "is-base64";

import { fetchInstallationToken } from "./fetch-installation-token.js";
Expand All @@ -24,11 +30,13 @@ try {
mode: installationRetrievalMode,
payload: installationRetrievalPayload,
});
debug(`Installation retrieval details: ${installationRetrievalDetails}.`);

const permissionsInput = getInput("permissions");
const permissions = permissionsInput
? (JSON.parse(permissionsInput) as Record<string, string>)
: undefined;
debug(`Requested permissions: ${permissions}.`);

const privateKeyInput = getInput("private_key", { required: true });
const privateKey = isBase64(privateKeyInput)
Expand All @@ -39,6 +47,7 @@ try {
const repositories = repositoriesInput
? (JSON.parse(repositoriesInput) as string[])
: undefined;
debug(`Requested repositories: ${permissions}.`);

const token = await fetchInstallationToken({
appId,
Expand All @@ -52,8 +61,8 @@ try {
setSecret(token);
setOutput("token", token);
info("Token generated successfully!");
} catch (_error: unknown) {
const error = ensureError(_error);
console.error(error);
} catch (error) {
// Using `console.error()` instead of only passing `error` to `setFailed()` for better error reporting.
console.debug(error);
setFailed("");
}
2 changes: 1 addition & 1 deletion src/installation-retrieval-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getInstallationRetrievalDetails = ({
}>): InstallationRetrievalDetails => {
switch (mode) {
case "id":
return { mode, id: Number(payload) };
return { mode, id: parseInt(payload) };
case "organization":
return { mode, org: payload };
case "repository":
Expand Down

0 comments on commit c2dc007

Please sign in to comment.