@@ -8822,6 +8822,117 @@ function wrappy (fn, cb) {
88228822}
88238823
88248824
8825+ /***/ }),
8826+
8827+ /***/ 4020:
8828+ /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
8829+
8830+ "use strict";
8831+
8832+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8833+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8834+ return new (P || (P = Promise))(function (resolve, reject) {
8835+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8836+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8837+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8838+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8839+ });
8840+ };
8841+ Object.defineProperty(exports, "__esModule", ({ value: true }));
8842+ const core_1 = __nccwpck_require__(2186);
8843+ class EnableGithubAutomergeAction {
8844+ constructor(client, context) {
8845+ this.client = client;
8846+ this.context = context;
8847+ }
8848+ run() {
8849+ return __awaiter(this, void 0, void 0, function* () {
8850+ // Find out where we are!
8851+ const { repo } = this.context;
8852+ if (!repo) {
8853+ throw new Error("Could not find repository!");
8854+ }
8855+ // Make sure this is actually a pull-request!
8856+ // We need this to retrieve the pull-request node ID.
8857+ const { pull_request: pullRequest } = this.context.payload;
8858+ if (!pullRequest) {
8859+ throw new Error("Event payload missing `pull_request`, is this a pull-request?");
8860+ }
8861+ const pullRequestId = pullRequest.node_id;
8862+ // Step 1. Retrieve the merge method!
8863+ core_1.debug(`Retrieving merge-method...`);
8864+ const mergeMethod = yield this.getMergeMethod(repo);
8865+ core_1.debug(`Successfully retrieved merge-method: ${mergeMethod}`);
8866+ // Step 2. Enable auto-merge.
8867+ core_1.debug(`Enabling auto-merge for pull-request #${pullRequest.number}`);
8868+ yield this.enableAutoMerge(pullRequestId, mergeMethod);
8869+ core_1.debug(`Successfully enabled auto-merge for pull-request #${pullRequest.number}`);
8870+ });
8871+ }
8872+ getMergeMethod(repo) {
8873+ var _a;
8874+ return __awaiter(this, void 0, void 0, function* () {
8875+ const preferredMergeMethod = core_1.getInput("merge-method", { required: false });
8876+ // Allow users to specify a merge method.
8877+ if (preferredMergeMethod) {
8878+ return preferredMergeMethod;
8879+ }
8880+ //
8881+ // Otherwise try and discover one.
8882+ //
8883+ // Merge is the default behaviour.
8884+ let mergeMethod = `MERGE`;
8885+ // Try to discover the repository's default merge method.
8886+ try {
8887+ const repositorySettings = yield this.client.graphql(`
8888+ query($repository: String!, $owner: String!) {
8889+ repository(name:$repository, owner:$owner) {
8890+ viewerDefaultMergeMethod
8891+ }
8892+ }
8893+ `, {
8894+ repository: repo.repo,
8895+ owner: repo.owner
8896+ });
8897+ const viewerDefaultMergeMethod = ((_a = repositorySettings === null || repositorySettings === void 0 ? void 0 : repositorySettings.repository) === null || _a === void 0 ? void 0 : _a.viewerDefaultMergeMethod) || undefined;
8898+ if (viewerDefaultMergeMethod) {
8899+ mergeMethod = viewerDefaultMergeMethod;
8900+ }
8901+ }
8902+ catch (err) {
8903+ core_1.error(`Failed to read default merge method: ${err.message}`);
8904+ }
8905+ return mergeMethod;
8906+ });
8907+ }
8908+ enableAutoMerge(pullRequestId, mergeMethod) {
8909+ return __awaiter(this, void 0, void 0, function* () {
8910+ return yield this.client.graphql(`
8911+ mutation(
8912+ $pullRequestId: ID!,
8913+ $mergeMethod: PullRequestMergeMethod!
8914+ ) {
8915+ enablePullRequestAutoMerge(input: {
8916+ pullRequestId: $pullRequestId,
8917+ mergeMethod: $mergeMethod
8918+ }) {
8919+ clientMutationId
8920+ pullRequest {
8921+ id
8922+ state
8923+ }
8924+ }
8925+ }
8926+ `, {
8927+ pullRequestId,
8928+ mergeMethod
8929+ });
8930+ });
8931+ }
8932+ }
8933+ exports.default = EnableGithubAutomergeAction;
8934+
8935+
88258936/***/ }),
88268937
88278938/***/ 399:
@@ -8857,42 +8968,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
88578968 step((generator = generator.apply(thisArg, _arguments || [])).next());
88588969 });
88598970};
8971+ var __importDefault = (this && this.__importDefault) || function (mod) {
8972+ return (mod && mod.__esModule) ? mod : { "default": mod };
8973+ };
88608974Object.defineProperty(exports, "__esModule", ({ value: true }));
8975+ exports.run = void 0;
88618976const core = __importStar(__nccwpck_require__(2186));
88628977const github = __importStar(__nccwpck_require__(5438));
8978+ const enable_github_automerge_action_1 = __importDefault(__nccwpck_require__(4020));
88638979function run() {
88648980 return __awaiter(this, void 0, void 0, function* () {
88658981 try {
8982+ const { context } = github;
88668983 const token = core.getInput("github-token", { required: true });
88678984 const client = github.getOctokit(token);
8868- const { pull_request: pr } = github.context.payload;
8869- if (!pr) {
8870- throw new Error("Event payload missing `pull_request`");
8871- }
8872- core.debug(`Enabling auto-merge for pull-request #${pr.number}`);
8873- client.graphql(`
8874- mutation {
8875- enablePullRequestAutoMerge(input:{
8876- pullRequestId: "${pr.node_id}"
8877- }) {
8878- actor {
8879- login
8880- }
8881- clientMutationId
8882- pullRequest {
8883- id
8884- state
8885- }
8886- }
8887- }
8888- `);
8889- core.debug(`Successfully enabled auto-merge for pull-request #${pr.number}`);
8985+ const automergeAction = new enable_github_automerge_action_1.default(client, context);
8986+ yield automergeAction.run();
88908987 }
88918988 catch (error) {
88928989 core.setFailed(error.message);
88938990 }
88948991 });
88958992}
8993+ exports.run = run;
88968994run();
88978995
88988996
0 commit comments