Skip to content

Commit

Permalink
Merge branch 'master' into Rory-FailActionWhenPRNotMergeable
Browse files Browse the repository at this point in the history
  • Loading branch information
roryabraham committed Jan 28, 2022
2 parents ba0316b + 0ba0473 commit be28fa3
Show file tree
Hide file tree
Showing 9 changed files with 3,537 additions and 1,575 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:stretch
- image: cimg/node:16.13.1
steps:
- checkout
- run:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ The following merge options are supported:
repositories. Set this option to `true` to automatically delete branches
after they have been merged. The default value is `false`.

- `MERGE_DELETE_BRANCH_FILTER`: A comma-separated list of branches that will not
be deleted. This is not the list of GitHub's protected branches, which are never
deleted, but an additional list of branches to protect. The default value is `""`.

The following update options are supported:

- `UPDATE_LABELS`: The labels that need to be present for a pull request to be
Expand Down Expand Up @@ -273,4 +277,4 @@ Install dependencies with `yarn`, and finally run `yarn it` (or `npm run it`).

## License

[MIT](LICENSE)
[MIT](./LICENSE)
44 changes: 44 additions & 0 deletions dist/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


tr46
MIT

universal-user-agent
ISC
# [ISC License](https://spdx.org/licenses/ISC)
Expand Down Expand Up @@ -1158,6 +1161,47 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


webidl-conversions
BSD-2-Clause
# The BSD 2-Clause License

Copyright (c) 2014, Domenic Denicola
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


whatwg-url
MIT
The MIT License (MIT)

Copyright (c) 2015–2016 Sebastian Mayr

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


wrappy
ISC
The ISC License
Expand Down
3,090 changes: 2,529 additions & 561 deletions dist/index.js

Large diffs are not rendered by default.

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

function parseMergeMethodLabels(str) {
if (!str) {
return [];
}
return str.split(",").map(lm => {
function parseLabelMethods(str) {
return (str ? str.split(",") : []).map(lm => {
const [label, method] = lm.split("=");
if (!label || !method) {
throw new Error(
Expand All @@ -84,8 +81,8 @@ function createConfig(env = {}) {
});
}

function parseMergeRemoveLabels(str, defaultValue) {
return (str == null ? defaultValue : str).split(",").map(s => s.trim());
function parseArray(str) {
return str ? str.split(",") : [];
}

function parsePositiveInt(name, defaultValue) {
Expand Down Expand Up @@ -147,7 +144,7 @@ function createConfig(env = {}) {
}

const mergeLabels = parseMergeLabels(env.MERGE_LABELS, "automerge");
const mergeRemoveLabels = parseMergeRemoveLabels(env.MERGE_REMOVE_LABELS, "");
const mergeRemoveLabels = parseArray(env.MERGE_REMOVE_LABELS);
const mergeMethod = env.MERGE_METHOD || "merge";
const mergeForks = env.MERGE_FORKS !== "false";
const mergeCommitMessage = env.MERGE_COMMIT_MESSAGE || "automatic";
Expand All @@ -160,7 +157,8 @@ function createConfig(env = {}) {
0
);
const mergeDeleteBranch = env.MERGE_DELETE_BRANCH === "true";
const mergeMethodLabels = parseMergeMethodLabels(env.MERGE_METHOD_LABELS);
const mergeDeleteBranchFilter = parseArray(env.MERGE_DELETE_BRANCH_FILTER);
const mergeMethodLabels = parseLabelMethods(env.MERGE_METHOD_LABELS);
const mergeMethodLabelRequired = env.MERGE_METHOD_LABEL_REQUIRED === "true";

const updateLabels = parseMergeLabels(env.UPDATE_LABELS, "automerge");
Expand All @@ -184,6 +182,7 @@ function createConfig(env = {}) {
mergeRetrySleep,
mergeRequiredApprovals,
mergeDeleteBranch,
mergeDeleteBranchFilter,
updateLabels,
updateMethod,
updateRetries,
Expand Down
31 changes: 19 additions & 12 deletions lib/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ async function merge(context, pullRequest, approvalCount) {

if (context.config.mergeDeleteBranch) {
try {
await deleteBranch(octokit, pullRequest);
await deleteBranch(
octokit,
pullRequest,
context.config.mergeDeleteBranchFilter
);
} catch (e) {
logger.info("Failed to delete branch:", e.message);
}
Expand Down Expand Up @@ -122,7 +126,7 @@ async function removeLabels(octokit, pullRequest, mergeRemoveLabels) {
logger.info("Removed labels:", labelNames);
}

async function deleteBranch(octokit, pullRequest) {
async function deleteBranch(octokit, pullRequest, mergeDeleteBranchFilter) {
if (pullRequest.head.repo.full_name !== pullRequest.base.repo.full_name) {
logger.info("Branch is from external repository, skipping delete");
return;
Expand All @@ -142,24 +146,27 @@ async function deleteBranch(octokit, pullRequest) {
const { data: protectionRules } = await octokit.repos.getBranchProtection(
branchQuery
);

if (
protectionRules.allow_deletions &&
!protectionRules.allow_deletions.enabled
) {
logger.info("Branch is protected and cannot be deleted:", branch.name);
return;
}
} else if (mergeDeleteBranchFilter.includes(branch.name)) {
logger.info(
"Branch is in filter list and will not be deleted:",
branch.name
);
} else {
logger.debug("Deleting branch", branch.name, "...");
await octokit.git.deleteRef({
owner: pullRequest.head.repo.owner.login,
repo: pullRequest.head.repo.name,
ref: `heads/${branch.name}`
});
logger.info("Merged branch has been deleted:", branch.name);
}

logger.debug("Deleting branch", branch.name, "...");
await octokit.git.deleteRef({
owner: pullRequest.head.repo.owner.login,
repo: pullRequest.head.repo.name,
ref: `heads/${branch.name}`
});

logger.info("Merged branch has been deleted:", branch.name);
}

function skipPullRequest(context, pullRequest, approvalCount) {
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
"prepublish": "yarn lint && yarn test && yarn compile"
},
"dependencies": {
"@octokit/rest": "^18.10.0",
"@octokit/rest": "^18.12.0",
"argparse": "^2.0.1",
"fs-extra": "^10.0.0",
"object-resolve-path": "^1.1.1",
"tmp": "^0.2.1"
},
"devDependencies": {
"@vercel/ncc": "^0.30.0",
"@vercel/ncc": "^0.33.1",
"dotenv": "^10.0.0",
"eslint": "^7.32.0",
"eslint-plugin-jest": "^24.4.0",
"jest": "^27.1.0",
"prettier": "^2.3.2"
"eslint": "^8.6.0",
"eslint-plugin-jest": "^25.3.4",
"jest": "^27.4.6",
"prettier": "^2.5.1"
},
"prettier": {
"trailingComma": "none",
Expand Down
12 changes: 8 additions & 4 deletions test/common.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ test("createConfig", () => {
mergeCommitMessage: "automatic",
mergeCommitMessageRegex: "",
mergeDeleteBranch: false,
mergeDeleteBranchFilter: [],
mergeRetries: 3,
mergeRetrySleep: 5000,
mergeRequiredApprovals: 0,
mergeRemoveLabels: [""],
mergeRemoveLabels: [],
updateMethod: "merge",
updateLabels: {
blocking: ["block1", "block2"],
Expand Down Expand Up @@ -55,10 +56,11 @@ test("createConfig with arbitrary pull request (as string)", () => {
mergeCommitMessage: "automatic",
mergeCommitMessageRegex: "",
mergeDeleteBranch: false,
mergeDeleteBranchFilter: [],
mergeRetries: 3,
mergeRetrySleep: 5000,
mergeRequiredApprovals: 0,
mergeRemoveLabels: [""],
mergeRemoveLabels: [],
updateMethod: "merge",
updateLabels: {
blocking: ["block1", "block2"],
Expand Down Expand Up @@ -93,10 +95,11 @@ test("createConfig with arbitrary pull request (as number)", () => {
mergeCommitMessage: "automatic",
mergeCommitMessageRegex: "",
mergeDeleteBranch: false,
mergeDeleteBranchFilter: [],
mergeRetries: 3,
mergeRetrySleep: 5000,
mergeRequiredApprovals: 0,
mergeRemoveLabels: [""],
mergeRemoveLabels: [],
updateMethod: "merge",
updateLabels: {
blocking: ["block1", "block2"],
Expand Down Expand Up @@ -131,10 +134,11 @@ test("createConfig with arbitrary pull request in another repo", () => {
mergeCommitMessage: "automatic",
mergeCommitMessageRegex: "",
mergeDeleteBranch: false,
mergeDeleteBranchFilter: [],
mergeRetries: 3,
mergeRetrySleep: 5000,
mergeRequiredApprovals: 0,
mergeRemoveLabels: [""],
mergeRemoveLabels: [],
updateMethod: "merge",
updateLabels: {
blocking: ["block1", "block2"],
Expand Down
Loading

0 comments on commit be28fa3

Please sign in to comment.