From 72579aa292668dcc54171ed61001adc614591547 Mon Sep 17 00:00:00 2001 From: Harry Marr Date: Mon, 15 Mar 2021 18:08:54 -0400 Subject: [PATCH] Re-build --- dist/index.js | 90 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 12 deletions(-) diff --git a/dist/index.js b/dist/index.js index e6110fc..371567b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5828,7 +5828,7 @@ function wrappy (fn, cb) { /***/ }), -/***/ 399: +/***/ 609: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; @@ -5862,31 +5862,97 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.approve = void 0; const core = __importStar(__nccwpck_require__(186)); const github = __importStar(__nccwpck_require__(438)); -function run() { +const request_error_1 = __nccwpck_require__(537); +function approve(token, context) { return __awaiter(this, void 0, void 0, function* () { + const { pull_request: pr } = context.payload; + if (!pr) { + core.setFailed("Event payload missing `pull_request` key. Make sure you're " + + "triggering this action on the `pull_request` or `pull_request_target` events."); + return; + } + const client = github.getOctokit(token); + core.info(`Creating approving review for pull request #${pr.number}`); try { - const token = core.getInput("github-token", { required: true }); - const { pull_request: pr } = github.context.payload; - if (!pr) { - throw new Error("Event payload missing `pull_request`"); - } - const client = github.getOctokit(token); - core.debug(`Creating approving review for pull request #${pr.number}`); yield client.pulls.createReview({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, + owner: context.repo.owner, + repo: context.repo.repo, pull_number: pr.number, event: "APPROVE", }); - core.debug(`Approved pull request #${pr.number}`); + core.info(`Approved pull request #${pr.number}`); } catch (error) { + if (error instanceof request_error_1.RequestError) { + switch (error.status) { + case 401: + core.setFailed(`${error.message}. Please check that the \`github-token\` input ` + + `parameter is set correctly.`); + case 403: + core.setFailed(`${error.message}. In some cases, the GitHub token used for actions triggered ` + + `from \`pull_request\` events are read-only, which can cause this problem. ` + + `Switching to the \`pull_request_target\` event typically resolves this issue.`); + default: + core.setFailed(`Error (code ${error.status}): ${error.message}`); + } + return; + } core.setFailed(error.message); + return; } }); } +exports.approve = approve; + + +/***/ }), + +/***/ 399: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +const core = __importStar(__nccwpck_require__(186)); +const github = __importStar(__nccwpck_require__(438)); +const approve_1 = __nccwpck_require__(609); +function run() { + return __awaiter(this, void 0, void 0, function* () { + const token = core.getInput("github-token", { required: true }); + yield approve_1.approve(token, github.context); + }); +} run();