@@ -63625,61 +63625,117 @@ const core = __importStar(__nccwpck_require__(2186));
6362563625const github = __importStar(__nccwpck_require__(5438));
6362663626const lib_1 = __nccwpck_require__(6791);
6362763627const track_1 = __nccwpck_require__(1263);
63628+ const jobID = (0, lib_1.optional)('codeball-job-id');
6362863629function run() {
6362963630 var _a, _b, _c, _d, _e, _f, _g;
6363063631 return __awaiter(this, void 0, void 0, function* () {
63631- try {
63632- const pullRequestURL = (_b = (_a = github.context.payload) === null || _a === void 0 ? void 0 : _a.pull_request) === null || _b === void 0 ? void 0 : _b.html_url;
63633- if (!pullRequestURL) {
63634- throw new Error('No pull request URL found');
63635- }
63636- const pullRequestNumber = (_d = (_c = github.context.payload) === null || _c === void 0 ? void 0 : _c.pull_request) === null || _d === void 0 ? void 0 : _d.number;
63637- if (!pullRequestNumber) {
63638- throw new Error('No pull request number found');
63639- }
63640- const commitId = (_e = github.context.payload.pull_request) === null || _e === void 0 ? void 0 : _e.head.sha;
63641- if (!commitId) {
63642- throw new Error('No commit ID found');
63643- }
63644- const repoOwner = (_f = github.context.payload.repository) === null || _f === void 0 ? void 0 : _f.owner.login;
63645- if (!repoOwner) {
63646- throw new Error('No repo owner found');
63647- }
63648- const repoName = (_g = github.context.payload.repository) === null || _g === void 0 ? void 0 : _g.name;
63649- if (!repoName) {
63650- throw new Error('No repo name found');
63651- }
63652- const githubToken = core.getInput('GITHUB_TOKEN');
63653- if (!githubToken) {
63654- core.setFailed('No GITHUB_TOKEN found');
63655- return;
63656- }
63657- const jobID = core.getInput('codeball-job-id'); // jobID is not required
63658- const octokit = new lib_1.Octokit({ auth: githubToken });
63659- yield octokit.pulls.createReview({
63660- owner: repoOwner,
63661- repo: repoName,
63662- pull_number: pullRequestNumber,
63663- commit_id: commitId,
63664- body: 'Codeball: LGTM! :+1:',
63665- event: 'APPROVE'
63666- });
63667- yield (0, track_1.track)(jobID, 'approver');
63668- }
63669- catch (error) {
63670- if (error instanceof Error) {
63671- if (error.message === 'Resource not accessible by integration') {
63672- core.error('Codeball Approver failed to access GitHub. Check the "GITHUB_TOKEN Permissions" of this job and make sure that the job has WRITE permissions to Pull Requests.');
63673- core.error(error);
63674- }
63675- else {
63676- core.setFailed(error.message);
63677- }
63678- }
63679- }
63632+ const pullRequestURL = (_b = (_a = github.context.payload) === null || _a === void 0 ? void 0 : _a.pull_request) === null || _b === void 0 ? void 0 : _b.html_url;
63633+ if (!pullRequestURL)
63634+ throw new Error('No pull request URL found');
63635+ const pullRequestNumber = (_d = (_c = github.context.payload) === null || _c === void 0 ? void 0 : _c.pull_request) === null || _d === void 0 ? void 0 : _d.number;
63636+ if (!pullRequestNumber)
63637+ throw new Error('No pull request number found');
63638+ const commitId = (_e = github.context.payload.pull_request) === null || _e === void 0 ? void 0 : _e.head.sha;
63639+ if (!commitId)
63640+ throw new Error('No commit ID found');
63641+ const repoOwner = (_f = github.context.payload.repository) === null || _f === void 0 ? void 0 : _f.owner.login;
63642+ if (!repoOwner)
63643+ throw new Error('No repo owner found');
63644+ const repoName = (_g = github.context.payload.repository) === null || _g === void 0 ? void 0 : _g.name;
63645+ if (!repoName)
63646+ throw new Error('No repo name found');
63647+ const githubToken = (0, lib_1.required)('GITHUB_TOKEN');
63648+ const octokit = new lib_1.Octokit({ auth: githubToken });
63649+ yield octokit.pulls.createReview({
63650+ owner: repoOwner,
63651+ repo: repoName,
63652+ pull_number: pullRequestNumber,
63653+ commit_id: commitId,
63654+ body: 'Codeball: LGTM! :+1:',
63655+ event: 'APPROVE'
63656+ });
6368063657 });
6368163658}
63682- run();
63659+ run()
63660+ .then(() => (0, track_1.track)({ jobID, actionName: 'approver' }))
63661+ .catch(error => {
63662+ if (error instanceof Error) {
63663+ (0, track_1.track)({ jobID, actionName: 'approver', error: error.message });
63664+ if (error.message === 'Resource not accessible by integration') {
63665+ core.setFailed('Codeball Approver failed to access GitHub. Check the "GITHUB_TOKEN Permissions" of this job and make sure that the job has WRITE permissions to Pull Requests.');
63666+ }
63667+ else {
63668+ core.setFailed(error.message);
63669+ }
63670+ }
63671+ });
63672+
63673+
63674+ /***/ }),
63675+
63676+ /***/ 7527:
63677+ /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
63678+
63679+ "use strict";
63680+
63681+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
63682+ if (k2 === undefined) k2 = k;
63683+ var desc = Object.getOwnPropertyDescriptor(m, k);
63684+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
63685+ desc = { enumerable: true, get: function() { return m[k]; } };
63686+ }
63687+ Object.defineProperty(o, k2, desc);
63688+ }) : (function(o, m, k, k2) {
63689+ if (k2 === undefined) k2 = k;
63690+ o[k2] = m[k];
63691+ }));
63692+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
63693+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
63694+ };
63695+ Object.defineProperty(exports, "__esModule", ({ value: true }));
63696+ __exportStar(__nccwpck_require__(8913), exports);
63697+
63698+
63699+ /***/ }),
63700+
63701+ /***/ 8913:
63702+ /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
63703+
63704+ "use strict";
63705+
63706+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
63707+ if (k2 === undefined) k2 = k;
63708+ var desc = Object.getOwnPropertyDescriptor(m, k);
63709+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
63710+ desc = { enumerable: true, get: function() { return m[k]; } };
63711+ }
63712+ Object.defineProperty(o, k2, desc);
63713+ }) : (function(o, m, k, k2) {
63714+ if (k2 === undefined) k2 = k;
63715+ o[k2] = m[k];
63716+ }));
63717+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
63718+ Object.defineProperty(o, "default", { enumerable: true, value: v });
63719+ }) : function(o, v) {
63720+ o["default"] = v;
63721+ });
63722+ var __importStar = (this && this.__importStar) || function (mod) {
63723+ if (mod && mod.__esModule) return mod;
63724+ var result = {};
63725+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
63726+ __setModuleDefault(result, mod);
63727+ return result;
63728+ };
63729+ Object.defineProperty(exports, "__esModule", ({ value: true }));
63730+ exports.optional = exports.required = void 0;
63731+ const core = __importStar(__nccwpck_require__(2186));
63732+ const required = (name) => core.getInput(name, { required: true });
63733+ exports.required = required;
63734+ const optional = (name) => {
63735+ const value = core.getInput(name, { required: false });
63736+ return value === '' ? undefined : value;
63737+ };
63738+ exports.optional = optional;
6368363739
6368463740
6368563741/***/ }),
@@ -63778,6 +63834,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
6377863834 for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
6377963835};
6378063836Object.defineProperty(exports, "__esModule", ({ value: true }));
63837+ __exportStar(__nccwpck_require__(7527), exports);
6378163838__exportStar(__nccwpck_require__(6518), exports);
6378263839__exportStar(__nccwpck_require__(3769), exports);
6378363840
@@ -63898,11 +63955,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
6389863955Object.defineProperty(exports, "__esModule", ({ value: true }));
6389963956exports.track = void 0;
6390063957const api_1 = __nccwpck_require__(9095);
63901- const track = (jobID, actionName) => __awaiter(void 0, void 0, void 0, function* () {
63958+ const track = ({ jobID, actionName, error } ) => __awaiter(void 0, void 0, void 0, function* () {
6390263959 return (0, api_1.post)("/track", {
63903- job_id: jobID,
63960+ job_id: jobID !== null && jobID !== void 0 ? jobID : null ,
6390463961 name: actionName,
63905- });
63962+ error: error !== null && error !== void 0 ? error : null
63963+ }).catch(error => console.warn(error));
6390663964});
6390763965exports.track = track;
6390863966
0 commit comments