@@ -128712,10 +128712,206 @@ try {
128712128712
128713128713/***/ }),
128714128714
128715- /***/ 1720:
128716- /***/ ((module) => {
128715+ /***/ 94850:
128716+ /***/ (function(module, exports) {
128717+
128718+ "use strict";
128717128719
128718- module.exports = eval("require")("./app");
128720+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
128721+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
128722+ return new (P || (P = Promise))(function (resolve, reject) {
128723+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
128724+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
128725+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
128726+ step((generator = generator.apply(thisArg, _arguments || [])).next());
128727+ });
128728+ };
128729+ var __generator = (this && this.__generator) || function (thisArg, body) {
128730+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
128731+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
128732+ function verb(n) { return function (v) { return step([n, v]); }; }
128733+ function step(op) {
128734+ if (f) throw new TypeError("Generator is already executing.");
128735+ while (_) try {
128736+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
128737+ if (y = 0, t) op = [op[0] & 2, t.value];
128738+ switch (op[0]) {
128739+ case 0: case 1: t = op; break;
128740+ case 4: _.label++; return { value: op[1], done: false };
128741+ case 5: _.label++; y = op[1]; op = [0]; continue;
128742+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
128743+ default:
128744+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
128745+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
128746+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
128747+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
128748+ if (t[2]) _.ops.pop();
128749+ _.trys.pop(); continue;
128750+ }
128751+ op = body.call(thisArg, _);
128752+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
128753+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
128754+ }
128755+ };
128756+ Object.defineProperty(exports, "__esModule", ({ value: true }));
128757+ module.exports = function (app) {
128758+ app.on(['pull_request.opened', 'pull_request.reopened', 'pull_request.labeled', 'pull_request.edited', 'pull_request_review'], function (context) { return __awaiter(void 0, void 0, void 0, function () {
128759+ var pr, config, prLabels, blacklistedLabels, ownerSatisfied, requiredLabelsSatisfied, appliedRequiredLabels, missingRequiredLabels, reviews;
128760+ return __generator(this, function (_a) {
128761+ switch (_a.label) {
128762+ case 0:
128763+ context.log('Repo: %s', context.payload.repository.full_name);
128764+ pr = context.payload.pull_request;
128765+ context.log('PR: %s', pr.html_url);
128766+ context.log('Action: %s', context.payload.action);
128767+ // NOTE(dabrady) When a PR is first opened, it can fire several different kinds of events if the author e.g. requests
128768+ // reviewers or adds labels during creation. This triggers parallel runs of our GitHub App, so we need to filter out
128769+ // those simultaneous events and focus just on the re/open event in this scenario.
128770+ //
128771+ // These simultaneous events contain the same pull request data in their payloads, and specify the 'updated at'
128772+ // timestamp to be the same as the 'created at' timestamp for the pull request. We can use this to distinguish events
128773+ // that are fired during creation from events fired later on.
128774+ if (!['opened', 'reopened'].includes(context.payload.action) && pr.created_at === pr.updated_at) {
128775+ context.log('Ignoring additional creation event: %s', context.payload.action);
128776+ return [2 /*return*/];
128777+ }
128778+ return [4 /*yield*/, context.config('autoapproval.yml')];
128779+ case 1:
128780+ config = _a.sent();
128781+ context.log(config, '\n\nLoaded config');
128782+ prLabels = pr.labels.map(function (label) { return label.name; });
128783+ blacklistedLabels = [];
128784+ if (config.blacklisted_labels !== undefined) {
128785+ blacklistedLabels = config.blacklisted_labels
128786+ .filter(function (blacklistedLabel) { return prLabels.includes(blacklistedLabel); });
128787+ // if PR contains any black listed labels, do not proceed further
128788+ if (blacklistedLabels.length > 0) {
128789+ context.log('PR black listed from approving: %s', blacklistedLabels);
128790+ return [2 /*return*/];
128791+ }
128792+ }
128793+ ownerSatisfied = config.from_owner.length === 0 || config.from_owner.includes(pr.user.login);
128794+ if (config.required_labels_mode === 'one_of') {
128795+ appliedRequiredLabels = config.required_labels
128796+ .filter(function (requiredLabel) { return prLabels.includes(requiredLabel); });
128797+ requiredLabelsSatisfied = appliedRequiredLabels.length > 0;
128798+ }
128799+ else {
128800+ missingRequiredLabels = config.required_labels
128801+ .filter(function (requiredLabel) { return !prLabels.includes(requiredLabel); });
128802+ requiredLabelsSatisfied = missingRequiredLabels.length === 0;
128803+ }
128804+ if (!(requiredLabelsSatisfied && ownerSatisfied)) return [3 /*break*/, 8];
128805+ return [4 /*yield*/, getAutoapprovalReviews(context)];
128806+ case 2:
128807+ reviews = _a.sent();
128808+ if (!(reviews.length > 0)) return [3 /*break*/, 5];
128809+ context.log('PR has already reviews');
128810+ if (!(context.payload.action === 'dismissed')) return [3 /*break*/, 4];
128811+ return [4 /*yield*/, applyAutoMerge(context, prLabels, config.auto_merge_labels, config.auto_rebase_merge_labels, config.auto_squash_merge_labels)];
128812+ case 3:
128813+ _a.sent();
128814+ approvePullRequest(context);
128815+ applyLabels(context, config.apply_labels);
128816+ context.log('Review was dismissed, approve again');
128817+ _a.label = 4;
128818+ case 4: return [3 /*break*/, 7];
128819+ case 5: return [4 /*yield*/, applyAutoMerge(context, prLabels, config.auto_merge_labels, config.auto_rebase_merge_labels, config.auto_squash_merge_labels)];
128820+ case 6:
128821+ _a.sent();
128822+ approvePullRequest(context);
128823+ applyLabels(context, config.apply_labels);
128824+ context.log('PR approved first time');
128825+ _a.label = 7;
128826+ case 7: return [3 /*break*/, 9];
128827+ case 8:
128828+ // one of the checks failed
128829+ context.log('Condition failed! \n - missing required labels: %s\n - PR owner found: %s', requiredLabelsSatisfied, ownerSatisfied);
128830+ _a.label = 9;
128831+ case 9: return [2 /*return*/];
128832+ }
128833+ });
128834+ }); });
128835+ };
128836+ function approvePullRequest(context) {
128837+ return __awaiter(this, void 0, void 0, function () {
128838+ var prParams;
128839+ return __generator(this, function (_a) {
128840+ switch (_a.label) {
128841+ case 0:
128842+ prParams = context.pullRequest({ event: 'APPROVE', body: 'Approved :+1:' });
128843+ return [4 /*yield*/, context.octokit.pulls.createReview(prParams)];
128844+ case 1:
128845+ _a.sent();
128846+ return [2 /*return*/];
128847+ }
128848+ });
128849+ });
128850+ }
128851+ function applyLabels(context, labels) {
128852+ return __awaiter(this, void 0, void 0, function () {
128853+ var labelsParam;
128854+ return __generator(this, function (_a) {
128855+ switch (_a.label) {
128856+ case 0:
128857+ if (!(labels.length > 0)) return [3 /*break*/, 2];
128858+ labelsParam = context.issue({ labels: labels });
128859+ return [4 /*yield*/, context.octokit.issues.addLabels(labelsParam)];
128860+ case 1:
128861+ _a.sent();
128862+ _a.label = 2;
128863+ case 2: return [2 /*return*/];
128864+ }
128865+ });
128866+ });
128867+ }
128868+ function applyAutoMerge(context, prLabels, mergeLabels, rebaseLabels, squashLabels) {
128869+ if (mergeLabels && prLabels.filter(function (label) { return mergeLabels.includes(label); }).length > 0) {
128870+ enableAutoMerge(context, 'MERGE');
128871+ }
128872+ if (rebaseLabels && prLabels.filter(function (label) { return rebaseLabels.includes(label); }).length > 0) {
128873+ enableAutoMerge(context, 'REBASE');
128874+ }
128875+ if (squashLabels && prLabels.filter(function (label) { return squashLabels.includes(label); }).length > 0) {
128876+ enableAutoMerge(context, 'SQUASH');
128877+ }
128878+ }
128879+ var enableAutoMergeMutation = "\n mutation($pullRequestId: ID!, $mergeMethod: PullRequestMergeMethod!) {\n enablePullRequestAutoMerge(input:{\n pullRequestId: $pullRequestId,\n mergeMethod: $mergeMethod\n }) {\n pullRequest {\n id,\n autoMergeRequest {\n mergeMethod\n }\n }\n }\n }\n";
128880+ function enableAutoMerge(context, method) {
128881+ return __awaiter(this, void 0, void 0, function () {
128882+ var payload;
128883+ return __generator(this, function (_a) {
128884+ switch (_a.label) {
128885+ case 0:
128886+ context.log('Auto merging with merge method %s', method);
128887+ payload = context.payload;
128888+ return [4 /*yield*/, context.octokit.graphql(enableAutoMergeMutation, {
128889+ pullRequestId: payload.pull_request.node_id,
128890+ mergeMethod: method
128891+ })];
128892+ case 1:
128893+ _a.sent();
128894+ return [2 /*return*/];
128895+ }
128896+ });
128897+ });
128898+ }
128899+ function getAutoapprovalReviews(context) {
128900+ return __awaiter(this, void 0, void 0, function () {
128901+ var pr, reviews, autoapprovalReviews;
128902+ return __generator(this, function (_a) {
128903+ switch (_a.label) {
128904+ case 0:
128905+ pr = context.pullRequest();
128906+ return [4 /*yield*/, context.octokit.pulls.listReviews(pr)];
128907+ case 1:
128908+ reviews = _a.sent();
128909+ autoapprovalReviews = (reviews.data).filter(function (item) { return item.user.login === 'autoapproval[bot]'; });
128910+ return [2 /*return*/, autoapprovalReviews];
128911+ }
128912+ });
128913+ });
128914+ }
128719128915
128720128916
128721128917/***/ }),
@@ -132481,7 +132677,7 @@ var __webpack_exports__ = {};
132481132677// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
132482132678(() => {
132483132679const { run } = __nccwpck_require__(12104)
132484- const app = __nccwpck_require__(1720 );
132680+ const app = __nccwpck_require__(94850 );
132485132681
132486132682run(app).catch((error) => {
132487132683 console.error(error);
0 commit comments