Skip to content

Commit

Permalink
Use ensure-error (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
tibdex authored Apr 9, 2022
1 parent 59c42b1 commit 6923e6a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 26 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-update",
"version": "2.1.4",
"version": "2.1.5",
"license": "MIT",
"type": "module",
"files": [
Expand All @@ -15,7 +15,8 @@
},
"dependencies": {
"@actions/core": "^1.6.0",
"@actions/github": "^5.0.1"
"@actions/github": "^5.0.1",
"ensure-error": "^4.0.0"
},
"devDependencies": {
"@octokit/openapi-types": "^11.2.0",
Expand Down
29 changes: 5 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
import {
getInput,
group,
info,
error as logError,
setFailed,
warning,
} from "@actions/core";
import { getInput, group, info, setFailed, warning } from "@actions/core";
import { context, getOctokit } from "@actions/github";
import type { GitHub } from "@actions/github/lib/utils.js";
import type { components } from "@octokit/openapi-types";
import type { PushEvent } from "@octokit/webhooks-definitions/schema.js";

const handleError = (
error: unknown,
{
handle = logError,
}: Readonly<{ handle?: (error: string | Error) => void }> = {},
) => {
if (typeof error !== "string" && !(error instanceof Error)) {
throw new TypeError(`Caught error of unexpected type: ${typeof error}`);
}

handle(error);
};
import ensureError from "ensure-error";

const unupdatablePullRequestCommentBody =
"Cannot auto-update because of conflicts.";
Expand Down Expand Up @@ -91,7 +72,7 @@ const handleUnupdatablePullRequest = async (

info(`Commented: ${newComment.html_url}`);
} catch (error: unknown) {
handleError(error, { handle: warning });
warning(ensureError(error));
}
};

Expand Down Expand Up @@ -130,7 +111,7 @@ const handlePullRequest = async (
);
info("Updated!");
} catch (error: unknown) {
handleError(error, { handle: warning });
warning(ensureError(error));
await handleUnupdatablePullRequest(pullRequest, { octokit });
}
},
Expand Down Expand Up @@ -175,7 +156,7 @@ const run = async () => {
await handlePullRequest(pullRequest, { eventPayload, octokit });
}
} catch (error: unknown) {
handleError(error, { handle: setFailed });
setFailed(ensureError(error));
}
};

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,11 @@ enhanced-resolve@^0.9.1:
memory-fs "^0.2.0"
tapable "^0.1.8"

ensure-error@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/ensure-error/-/ensure-error-4.0.0.tgz#8c7aedefd5a1f37c6802ff0bbc3cee726583388c"
integrity sha512-7Xenn3+R6tp2UqAbH9Jqs6QCSABQok+1VAhaPaF0jjm3iuhVHCblfBh18nYtpm3K9/V4Jpxz1JIqFZyrjstBtw==

env-editor@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/env-editor/-/env-editor-1.0.0.tgz#a7de585a96f0198d9ba20a786c17a691c53afaab"
Expand Down

0 comments on commit 6923e6a

Please sign in to comment.