From b01a479fd0d469378d711c1a77e70a28df66248f Mon Sep 17 00:00:00 2001 From: Harry Marr Date: Sat, 2 Apr 2022 14:41:51 +0100 Subject: [PATCH 1/3] Use node 16 --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 92117e0..87693e6 100644 --- a/action.yml +++ b/action.yml @@ -11,5 +11,5 @@ inputs: description: '(optional) The ID of a pull request to auto-approve. By default, this action tries to use the pull_request event payload.' required: false runs: - using: 'node12' + using: 'node16' main: 'dist/index.js' From 660ab934ba555586962255a3e0ac795343bb6d89 Mon Sep 17 00:00:00 2001 From: Harry Marr Date: Sat, 2 Apr 2022 14:42:04 +0100 Subject: [PATCH 2/3] Handle top-level errors --- dist/index.js | 22 ++++++++++++++++------ src/main.ts | 20 ++++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/dist/index.js b/dist/index.js index 30c4940..4a7518a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -8474,13 +8474,23 @@ const github = __importStar(__nccwpck_require__(5438)); const approve_1 = __nccwpck_require__(6609); function run() { return __awaiter(this, void 0, void 0, function* () { - const token = core.getInput("github-token", { required: true }); - const prNumber = parseInt(core.getInput("pull-request-number"), 10); - if (!Number.isNaN(prNumber)) { - yield (0, approve_1.approve)(token, github.context, prNumber); + try { + const token = core.getInput("github-token", { required: true }); + const prNumber = parseInt(core.getInput("pull-request-number"), 10); + if (!Number.isNaN(prNumber)) { + yield (0, approve_1.approve)(token, github.context, prNumber); + } + else { + yield (0, approve_1.approve)(token, github.context); + } } - else { - yield (0, approve_1.approve)(token, github.context); + catch (error) { + if (error instanceof Error) { + core.setFailed(error.message); + } + else { + core.setFailed("Unknown error"); + } } }); } diff --git a/src/main.ts b/src/main.ts index fec0ac5..fca4a3f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,12 +3,20 @@ import * as github from "@actions/github"; import { approve } from "./approve"; async function run() { - const token = core.getInput("github-token", { required: true }); - const prNumber: number = parseInt(core.getInput("pull-request-number"), 10); - if (!Number.isNaN(prNumber)) { - await approve(token, github.context, prNumber); - } else { - await approve(token, github.context); + try { + const token = core.getInput("github-token", { required: true }); + const prNumber: number = parseInt(core.getInput("pull-request-number"), 10); + if (!Number.isNaN(prNumber)) { + await approve(token, github.context, prNumber); + } else { + await approve(token, github.context); + } + } catch (error) { + if (error instanceof Error) { + core.setFailed(error.message); + } else { + core.setFailed("Unknown error"); + } } } From 38ef0a5e47ce559aadef76f1b13b14ca65ee8166 Mon Sep 17 00:00:00 2001 From: Harry Marr Date: Sat, 2 Apr 2022 14:49:58 +0100 Subject: [PATCH 3/3] Mark dist/index.js as generated --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..55b01a8 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +dist/index.js linguist-generated=true