Skip to content

Commit

Permalink
Add support for MERGE_READY_STATE option (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
BigGillyStyle committed Feb 18, 2023
1 parent eb68b06 commit 5407b38
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ The following merge options are supported:
- `MERGE_ERROR_FAIL`: Set this to `true` to have the action exit with error code `1`
when the pull request could not be merged successfully during a run.

- `MERGE_READY_STATE`: The state(s) of a pull request for which to attempt a
merge. This option can be a comma-separated list of states that will be considered mergeable.
The default value is `clean,has_hooks,unknown,unstable`.

The following update options are supported:

- `UPDATE_LABELS`: The labels that need to be present for a pull request to be
Expand Down
23 changes: 16 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,8 @@ function createConfig(env = {}) {
});
}

function parseArray(str) {
return str ? str.split(",") : [];
function parseArray(str, defaultArray = []) {
return str ? str.split(",") : defaultArray;
}

function parseBranches(str, defaultValue) {
Expand Down Expand Up @@ -665,6 +665,12 @@ function createConfig(env = {}) {
const mergeMethodLabels = parseLabelMethods(env.MERGE_METHOD_LABELS);
const mergeMethodLabelRequired = env.MERGE_METHOD_LABEL_REQUIRED === "true";
const mergeErrorFail = env.MERGE_ERROR_FAIL === "true";
const mergeReadyState = parseArray(env.MERGE_READY_STATE, [
"clean",
"has_hooks",
"unknown",
"unstable"
]);

const updateLabels = parseMergeLabels(env.UPDATE_LABELS, "automerge");
const updateMethod = env.UPDATE_METHOD || "merge";
Expand All @@ -691,6 +697,7 @@ function createConfig(env = {}) {
mergeDeleteBranch,
mergeDeleteBranchFilter,
mergeErrorFail,
mergeReadyState,
updateLabels,
updateMethod,
updateRetries,
Expand Down Expand Up @@ -983,7 +990,6 @@ const {
retry
} = __nccwpck_require__(6979);

const MAYBE_READY = ["clean", "has_hooks", "unknown", "unstable"];
const NOT_READY = ["dirty", "draft"];

const PR_PROPERTY = new RegExp("{pullRequest.([^}]+)}", "g");
Expand Down Expand Up @@ -1253,12 +1259,15 @@ function checkReady(pullRequest, context) {
if (skipPullRequest(context, pullRequest)) {
return "failure";
}
return mergeable(pullRequest);
return mergeable(pullRequest, context);
}

function mergeable(pullRequest) {
function mergeable(pullRequest, context) {
const { mergeable_state } = pullRequest;
if (mergeable_state == null || MAYBE_READY.includes(mergeable_state)) {
const {
config: { mergeReadyState }
} = context;
if (mergeable_state == null || mergeReadyState.includes(mergeable_state)) {
logger.info("PR is probably ready: mergeable_state:", mergeable_state);
return "success";
} else if (NOT_READY.includes(mergeable_state)) {
Expand Down Expand Up @@ -23227,7 +23236,7 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
/***/ ((module) => {

"use strict";
module.exports = JSON.parse('{"name":"automerge-action","version":"0.15.4","description":"GitHub action to automatically merge pull requests","main":"lib/api.js","author":"Pascal","license":"MIT","private":true,"bin":{"automerge-action":"./bin/automerge.js"},"scripts":{"test":"jest","it":"node it/it.js","lint":"prettier -l lib/** test/** && eslint .","compile":"ncc build bin/automerge.js --license LICENSE -o dist","prepublish":"yarn lint && yarn test && yarn compile"},"dependencies":{"@actions/core":"^1.10.0","@octokit/rest":"^19.0.5","argparse":"^2.0.1","fs-extra":"^10.1.0","object-resolve-path":"^1.1.1","tmp":"^0.2.1"},"devDependencies":{"@vercel/ncc":"^0.34.0","dotenv":"^16.0.3","eslint":"^8.25.0","eslint-plugin-jest":"^27.1.2","jest":"^29.2.0","prettier":"^2.7.1"},"prettier":{"trailingComma":"none","arrowParens":"avoid"}}');
module.exports = JSON.parse('{"name":"automerge-action","version":"0.15.5","description":"GitHub action to automatically merge pull requests","main":"lib/api.js","author":"Pascal","license":"MIT","private":true,"bin":{"automerge-action":"./bin/automerge.js"},"scripts":{"test":"jest","it":"node it/it.js","lint":"prettier -l lib/** test/** && eslint .","compile":"ncc build bin/automerge.js --license LICENSE -o dist","prepublish":"yarn lint && yarn test && yarn compile"},"dependencies":{"@actions/core":"^1.10.0","@octokit/rest":"^19.0.5","argparse":"^2.0.1","fs-extra":"^10.1.0","object-resolve-path":"^1.1.1","tmp":"^0.2.1"},"devDependencies":{"@vercel/ncc":"^0.34.0","dotenv":"^16.0.3","eslint":"^8.25.0","eslint-plugin-jest":"^27.1.2","jest":"^29.2.0","prettier":"^2.7.1"},"prettier":{"trailingComma":"none","arrowParens":"avoid"}}');

/***/ })

Expand Down
11 changes: 9 additions & 2 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ function createConfig(env = {}) {
});
}

function parseArray(str) {
return str ? str.split(",") : [];
function parseArray(str, defaultArray = []) {
return str ? str.split(",") : defaultArray;
}

function parseBranches(str, defaultValue) {
Expand Down Expand Up @@ -172,6 +172,12 @@ function createConfig(env = {}) {
const mergeMethodLabels = parseLabelMethods(env.MERGE_METHOD_LABELS);
const mergeMethodLabelRequired = env.MERGE_METHOD_LABEL_REQUIRED === "true";
const mergeErrorFail = env.MERGE_ERROR_FAIL === "true";
const mergeReadyState = parseArray(env.MERGE_READY_STATE, [
"clean",
"has_hooks",
"unknown",
"unstable"
]);

const updateLabels = parseMergeLabels(env.UPDATE_LABELS, "automerge");
const updateMethod = env.UPDATE_METHOD || "merge";
Expand All @@ -198,6 +204,7 @@ function createConfig(env = {}) {
mergeDeleteBranch,
mergeDeleteBranchFilter,
mergeErrorFail,
mergeReadyState,
updateLabels,
updateMethod,
updateRetries,
Expand Down
10 changes: 6 additions & 4 deletions lib/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const {
retry
} = require("./common");

const MAYBE_READY = ["clean", "has_hooks", "unknown", "unstable"];
const NOT_READY = ["dirty", "draft"];

const PR_PROPERTY = new RegExp("{pullRequest.([^}]+)}", "g");
Expand Down Expand Up @@ -279,12 +278,15 @@ function checkReady(pullRequest, context) {
if (skipPullRequest(context, pullRequest)) {
return "failure";
}
return mergeable(pullRequest);
return mergeable(pullRequest, context);
}

function mergeable(pullRequest) {
function mergeable(pullRequest, context) {
const { mergeable_state } = pullRequest;
if (mergeable_state == null || MAYBE_READY.includes(mergeable_state)) {
const {
config: { mergeReadyState }
} = context;
if (mergeable_state == null || mergeReadyState.includes(mergeable_state)) {
logger.info("PR is probably ready: mergeable_state:", mergeable_state);
return "success";
} else if (NOT_READY.includes(mergeable_state)) {
Expand Down
4 changes: 4 additions & 0 deletions test/common.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ test("createConfig", () => {
mergeDeleteBranch: false,
mergeDeleteBranchFilter: [],
mergeErrorFail: false,
mergeReadyState: ["clean", "has_hooks", "unknown", "unstable"],
mergeRetries: 3,
mergeRetrySleep: 5000,
mergeRequiredApprovals: 0,
Expand Down Expand Up @@ -61,6 +62,7 @@ test("createConfig with arbitrary pull request (as string)", () => {
mergeDeleteBranch: false,
mergeDeleteBranchFilter: [],
mergeErrorFail: false,
mergeReadyState: ["clean", "has_hooks", "unknown", "unstable"],
mergeRetries: 3,
mergeRetrySleep: 5000,
mergeRequiredApprovals: 0,
Expand Down Expand Up @@ -102,6 +104,7 @@ test("createConfig with arbitrary pull request (as number)", () => {
mergeDeleteBranch: false,
mergeDeleteBranchFilter: [],
mergeErrorFail: false,
mergeReadyState: ["clean", "has_hooks", "unknown", "unstable"],
mergeRetries: 3,
mergeRetrySleep: 5000,
mergeRequiredApprovals: 0,
Expand Down Expand Up @@ -143,6 +146,7 @@ test("createConfig with arbitrary pull request in another repo", () => {
mergeDeleteBranch: false,
mergeDeleteBranchFilter: [],
mergeErrorFail: false,
mergeReadyState: ["clean", "has_hooks", "unknown", "unstable"],
mergeRetries: 3,
mergeRetrySleep: 5000,
mergeRequiredApprovals: 0,
Expand Down

0 comments on commit 5407b38

Please sign in to comment.