From f5d0e59a14f6be507aecaeda50bb20df928e65a9 Mon Sep 17 00:00:00 2001 From: colbynh Date: Thu, 10 Feb 2022 15:25:49 -0500 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit d0b9bd7cd068143f585c3813666bfde6fe5da98d Merge: e0b037f 90c0d60 Author: colbynh Date: Thu Feb 10 15:21:16 2022 -0500 Merge branch 'add-exclude-open-prs' of github.com:recurforever/delete-old-branches-action into add-exclude-open-prs commit e0b037f1189246b95372c785988d896200a6b740 Author: Siavash Safi Date: Fri Feb 4 11:14:49 2022 +0100 parent 5ca4d860c3efd4b9e7fe703977d64331688970b6 author Siavash Safi 1643969689 +0100 committer colbynh 1644524340 -0500 gpgsig -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEUZBe8tgy7Ask2IhkIqPSM0dKGa8FAmIFczUACgkQIqPSM0dK Ga9Ltw/+NagoL6pRjUq2J/H/1YnsIEUzm8Hs7m7t4cMhOi8EoeRqhJ7i8xf5Cx4m Bdj4+5E7/x6oPXp+tZlZI0jp5Q6ZKlAcYxK4t41QpIe9sEiTy/3OFvY+22GQHjzL Ec9Agvj8psmlmGrCJdLNzdMD83+s+NJiPAyt3djZkQHKtIn4ssRDZKrS2aXJtDtz SlkdeeG4buaQv+/eV0gEIihKnsV/lqL7BedF7TcxFsxG6TcLMKrVYQ1f7qYGQu+U rDuyoc86IZR+ikrSVGFsNYZrbyFnwyGR7fTw8T3UqvUzmMgfA6Ba9vmxsB8JTRw3 oFXT3QK7dcPYS8wdYDtLd0ooIJO4sj8gJ9gPt/2UEU02ESFQ5Kr/fLKfJ2m2rlyl K4x+1eTSg4IADZ9woR3OJK1RHupxLJUEEwShn29dv8DWCp0LrG64FnPbmnb64rAT /AUTzbdwpVvs6UdlwDRIDWIa9vZqTn3pq9bN9QXAo3j585birKybNpPDnlvzFXls 0hhenZ04gt2V+qoRAAqEPg7wKFki89evmMjjsBG2Nzsw4HvS49Hou4pkiifCTlQC B0uUTE19a+sGjvA72gCozQO8EgOy34e36JBgSsfxd4ClrGX329cfJxfbezOwDAcp po0UfnQqGAJsjKcIS1K6P3Hw6DyroX0ZbT9oBnMjleBcoMh0xkE= =3gCj -----END PGP SIGNATURE----- parent 5ca4d860c3efd4b9e7fe703977d64331688970b6 author Siavash Safi 1643969689 +0100 committer colbynh 1644524337 -0500 gpgsig -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEUZBe8tgy7Ask2IhkIqPSM0dKGa8FAmIFczEACgkQIqPSM0dK Ga/QPQ//UIL+chY1ZJ8Pj4eSionib0n8Cx6lR81jH9No5ldilFxJQyWYFamPSnQc KU3YRyxPUIoq5vNp7+HgaNhLTRMfkjtEBrpu5M+0FVjQnCFaYjR0YW4zX3u/F4ct d9mzrzWjIWPZuFgQu/VAcB1NwEgB0l8nfVKJkSNAbuei8rddu4LFGp/fupWpW8tQ JIdigISNf2XrpOXZwfR09FVPAhU6+73VWlu0nqfuF69MA62BvxLaJKMaGAKzTKhv V4OzC0gq30bQi176nsUlgiJnhK9JDO9G/54/pbytWsOE/ZoZlW9rgZo8DzFnwJ7Y ZWLLDtor8KSx1Q844VtmrBuIESnWPCQwYxeNiumJpYDTe/ErSqG0bNxJep+GNF7y XxT77diZNWqI9cCgwj0EauAfbj7ssfYZyy/o35lAWQXlTy88E2SW2LEqjEv+PGrA xUcYbXunr/FeXaZsWzdVh0//hn3qKr6x//OVKMd+8sYv4yfweVVZGCKNlqAfNfi9 bquDtVhY8UOMb2jYwvW9zXaGBg7JNA2z9zyicRRdq7ssehrSjvFTZlP2U+bRC5Hz 46bGTMqeJNuikXD3N5vhSFBG2wPlMoDm9KFXkrP9DhRg0KBBQMPBYYvspsEtKoxY 3YMEibCaC/JGBjpPu4fgwfNQxJBxOhewY5aIL5VMan9kDsQGRlk= =8dYu -----END PGP SIGNATURE----- parent 5ca4d860c3efd4b9e7fe703977d64331688970b6 author Siavash Safi 1643969689 +0100 committer colbynh 1644524332 -0500 gpgsig -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEUZBe8tgy7Ask2IhkIqPSM0dKGa8FAmIFcy0ACgkQIqPSM0dK Ga+PChAAq3IhiKxPmxgY6i7ilvv25W0hndHI7pvCBXo8ckmxboDs0o85QEyRL0vm bNxHxVHeIC2qN6dOG5n4g6N4uxRCjRDpN1nu/FgYuHZ46EkNaPBe5B6GTW7i8nFV KVnj18mMNzfRrB3mVKxr4Af8S5GLVZ5qlxPATkZ9DJRIsrJxcT/IkCOXqXYNl1kY 2dlYR3NLKmCCKJSfLP88SiYxY3jIGOE1nkTuP3w+hZrNBkqPnRCbbFOoQmYnovDe JJRAzXtIwZL9qgIN7E0v9O8TLM5UI9FFk0gvNvTS2AWk4I4ZjSR/I2QQQhpBP9Ce EgBpE8oW/0Qll0jSKVDCseYycTVL9g+56N7jR52mT14Ju6uRqkrrQmtuPjPATp7O i6HG7ws/QTNPr74ophVxfIsZy4N4XPPU9KTyag9cxOlJCZEpioEctJ0W3fVQfp3N oLJWyjiDGmrRCaanW8UatTBTAv//imLOmEOGkDotg39MAdO2mch+ATGVdWaPNEqc rXh6rkGBui0xSOtT1h3IjpVBy/vKBCyEZZdO+q9lBn1iVPvTMr53pKDxtCoBznzl 35k1WWKY1W4mL7urhxM0pOqZq5ubY0kHRc5g9SP2CKAq3rtg8P+DFBvS8ab6Y/eC dPvftwTBb6YHR6uWF2CbklHhxhDBDTpXzI4lo0h6g9hXQVB17dQ= =YC59 -----END PGP SIGNATURE----- Update CODEOWNERS Use github api to get source branches Debug pr output debug . Fix api url Trim quotes on branch names Update for consistency Co-authored-by: Polykarpos Kossyfas <44210251+pkossyfas@users.noreply.github.com> Fix variable Co-authored-by: Polykarpos Kossyfas <44210251+pkossyfas@users.noreply.github.com> Update readme with exlude pr branches Update readme Update for consistency Co-authored-by: Polykarpos Kossyfas <44210251+pkossyfas@users.noreply.github.com> Fix variable Co-authored-by: Polykarpos Kossyfas <44210251+pkossyfas@users.noreply.github.com> commit 90c0d6046214d2de2e55398d51d33c3b2c01695c Merge: e3a2c01 0704ae2 Author: colbynh Date: Thu Feb 10 15:12:02 2022 -0500 Merge branch 'add-exclude-open-prs' of github.com:recurforever/delete-old-branches-action into add-exclude-open-prs commit e3a2c015f4bd4752a2c8ae29c600267509fa549e Author: colbynh Date: Thu Feb 10 15:11:44 2022 -0500 Add exclude pr commit 0704ae2b938fb5ac9524e37cc3851aff27c2719d Merge: 173fad9 c94dd47 Author: colbynh Date: Thu Feb 10 15:06:42 2022 -0500 Merge branch 'add-exclude-open-prs' of github.com:recurforever/delete-old-branches-action into add-exclude-open-prs commit 173fad9ef6c8a8d9ee679179b6057c959c5807a1 Author: Colby Chenard Date: Thu Feb 10 14:48:32 2022 -0500 Fix variable Co-authored-by: Polykarpos Kossyfas <44210251+pkossyfas@users.noreply.github.com> commit 2153840df6c2c88aa9ab7401758af23e5c510158 Author: Colby Chenard Date: Thu Feb 10 14:48:21 2022 -0500 Update for consistency Co-authored-by: Polykarpos Kossyfas <44210251+pkossyfas@users.noreply.github.com> commit c876f8807df6c88381c77f93e0ede676dc8da729 Author: colbynh Date: Wed Jan 26 15:37:16 2022 -0500 Update readme commit c86b44a310dd7f590b5226e4914588e2f59a6668 Author: colbynh Date: Wed Jan 26 15:33:05 2022 -0500 Trim quotes on branch names commit 0251ed91ce1bf0debd88d2b0ab55504f22a968f9 Author: colbynh Date: Wed Jan 26 13:18:59 2022 -0500 Fix api url commit dc20febf84447f4566a5f4c6da64153481b185e5 Author: colbynh Date: Wed Jan 26 13:17:02 2022 -0500 . commit ef515cdebb21af980d389e1151d1218e6c904cd0 Author: colbynh Date: Wed Jan 26 13:13:19 2022 -0500 debug commit c6e5632a95862dc550b244520f0bbe7f7a316c52 Author: colbynh Date: Wed Jan 26 12:58:27 2022 -0500 Debug pr output commit 5c69752d6c4edd5aeb2d83ba8eda21cc27022209 Author: colbynh Date: Wed Jan 26 12:44:42 2022 -0500 Update readme with exlude pr branches commit bfed45969b5204b68a0a98f5f9a21a717c49efaf Author: colbynh Date: Wed Jan 26 12:44:24 2022 -0500 Use github api to get source branches commit f58a23df148a7efe469ea07df112c03c0dc3d620 Author: colbynh Date: Wed Jan 26 12:04:43 2022 -0500 Add exclude pr branch option commit c94dd47310cf72e071f44a58bf8f1ffbe7148302 Author: Colby Chenard Date: Thu Feb 10 14:48:32 2022 -0500 Fix variable Co-authored-by: Polykarpos Kossyfas <44210251+pkossyfas@users.noreply.github.com> commit 2bb3f87ad41c84d45c7521c03ac62913951acc2e Author: Colby Chenard Date: Thu Feb 10 14:48:21 2022 -0500 Update for consistency Co-authored-by: Polykarpos Kossyfas <44210251+pkossyfas@users.noreply.github.com> commit 90dde1457952b0adaa65aa520bb3a7685e0662f7 Merge: e2fc70d ee268fd Author: Polykarpos Kossyfas <44210251+pkossyfas@users.noreply.github.com> Date: Tue Feb 8 12:56:13 2022 +0200 Merge pull request #15 from pkossyfas/protect-default-branch delete-old-branches: Protect main and master branch commit ee268fdcca5b481368bcf4a8e7fd760a079278eb Author: Polykarpos Kossyfas Date: Wed Feb 2 20:06:36 2022 +0200 delete-old-branches: Protect main and master branch Add main and master branches as default branches so as to be excluded from deletion. Also, add an option for user to override the default behavior. commit e2fc70df2ebc5528e6a963a9b9433e057b2d61ff Merge: 5cec5e4 9104e84 Author: Alexios Polyzos Date: Tue Feb 8 12:32:11 2022 +0200 Merge pull request #16 from hwoarang/markos/add-ability-to-exclude-tags delete-action-branches: Add ability to exclude certain tags pattern commit 9104e84624278f08813fd0fb7a0b6e643c3cb64f Author: Markos Chandras Date: Mon Feb 7 17:22:30 2022 +0200 delete-action-branches: Add ability to exclude certain tags pattern There might be cases where certain tags need to be excluded from deletion. As such, lets add the ability to do that similarly to how excluded branches are handled. commit 5cec5e4672485204d22ffc9dc80d49bc1ba09133 Author: Siavash Safi Date: Fri Feb 4 11:14:49 2022 +0100 Update CODEOWNERS commit 7e81c4d12badfd1159979ebedaf4ebcc8f812065 Author: colbynh Date: Wed Jan 26 15:37:16 2022 -0500 Update readme commit 6925fe23796cf942e75a1a018032e8f415944c6b Author: colbynh Date: Wed Jan 26 15:33:05 2022 -0500 Trim quotes on branch names commit 5e942cdc1b3bd13aaf7854760dba424ab17dce64 Author: colbynh Date: Wed Jan 26 13:18:59 2022 -0500 Fix api url commit 5498e08b215ab04838c21bf208212311f82559b9 Author: colbynh Date: Wed Jan 26 13:17:02 2022 -0500 . commit d19ff4adc04bb2743a92c1c93cd9251416b87774 Author: colbynh Date: Wed Jan 26 13:13:19 2022 -0500 debug commit 7c4e5a628c9d41c0a8cf8248ecc789f0eae20245 Author: colbynh Date: Wed Jan 26 12:58:27 2022 -0500 Debug pr output commit 3c95920ef6b88a336f197f4db28890080cdf6571 Author: colbynh Date: Wed Jan 26 12:44:42 2022 -0500 Update readme with exlude pr branches commit 5ca4d860c3efd4b9e7fe703977d64331688970b6 Author: colbynh Date: Wed Jan 26 12:44:24 2022 -0500 Use github api to get source branches commit e3f06507d436cd99dbe9a66a853a22277b53d239 Author: colbynh Date: Wed Jan 26 12:04:43 2022 -0500 Add exclude pr branch option commit 2f9019148d8d00048ab9dd8bfeed4adb2baa878d Merge: 6a6405f 6178899 Author: Markos Chandras Date: Mon Mar 15 07:34:01 2021 +0000 Merge pull request #12 from mdelapenya/patch-1 docs: update example usage to latest version commit 6178899abf72c9e28c0d57dfe265a21194f7fef8 Author: Manuel de la Peña Date: Mon Mar 15 07:34:40 2021 +0100 docs: update example usage to latest version commit 6a6405f48d7153ea329a9b9f241c03ab3df48404 Author: Markos Chandras Date: Tue Dec 1 11:50:54 2020 +0000 [github] Update release action Update action to use the beatlabs/release-changelog-action to generate the changelog for the release. commit b0c103860235b0f9a396326d8d0c7cacc0eb7662 Merge: ea9b1ff 32c8b35 Author: Markos Chandras Date: Tue Dec 1 11:46:34 2020 +0000 Merge pull request #9 from beatlabs/fix-excluded-branches-regex delete-old-branches: Fix default regex for excluded branches commit 32c8b35369344b487e62c5fc649d9c68e0b990d5 Author: Markos Chandras Date: Tue Dec 1 10:18:45 2020 +0000 delete-old-branches: Fix default regex for excluded branches The default regex is meant to not ignore any extra branch. As such, we need fix the regex in order to not match anything. commit ea9b1ff04e177ed97b650075a76b6fb81ac9a50e Author: Markos Chandras Date: Tue Nov 24 15:57:47 2020 +0000 [github] Bump to latest release action commit e78d12655eeae6d80ec8fc8aa608fc8c4b3f9419 Merge: ab4c664 eab41eb Author: Markos Chandras Date: Tue Nov 24 15:43:20 2020 +0000 Merge pull request #8 from beatlabs/minimum_tags [delete-old-branches] Add option to keep minimum number of tags commit eab41eb2bb616886dc89d57dd07cfd71ffe8f63e Author: Markos Chandras Date: Tue Nov 10 22:44:55 2020 +0000 [delete-old-branches] Add option to keep minimum number of tags Tags often correspond to actual releases so its might be desirable to keep a minimum number of them around especially for repositories which do not release so often otheriwse we may end up with a situation where all the tags will be eventually deleted if nothing was committed to the repo for X amount of time. commit ab4c664018a4bcc1ed7f8f9156552d6016bd3a1b Merge: 68dfdde fb75cf4 Author: Markos Chandras Date: Tue Nov 10 22:33:32 2020 +0000 Merge pull request #6 from beatlabs/fix-logic-around-branch-prefix Fix logic around prefixed branches commit fb75cf4f964949aa407728e6cef3416c40da05cb Author: Markos Chandras Date: Fri Jul 24 13:12:20 2020 +0300 Fix logic around prefixed branches The action deletes all branches by default except the protected ones. As such, there is no reason to have a specific filter to include more branches into this logic. What we want is a mechanism to *exclude* branches from this logic in order to artifically protect branches which are not marked as protected in the github API. commit 68dfddeca2bf3214a87039472c3b55609749b821 Author: Markos Chandras Date: Mon Sep 14 16:38:33 2020 +0300 [github] Update SHA for release action Update SHA for the release action which fixes the following problem: marvinpinto/action-automatic-releases/7787f7d200d647f2e8739c9df73a1cf7a23b9f30/action.yml (Line: 27, Col: 5): Unexpected value 'decription' commit ae017843de8b65ef53c7795b8106bcf2c7bca719 Merge: 801baf5 37542d5 Author: Markos Chandras Date: Mon Sep 14 14:36:20 2020 +0100 Merge pull request #7 from beatlabs/hide-pseudorefs-and-peeled-tags Pass --refs to git-ls-remote commit 37542d58b0bedab09ff84b4617b83a19b325191a Author: Markos Chandras Date: Mon Sep 14 13:35:35 2020 +0300 Pass --refs to git-ls-remote We need to pass --refs to the git ls-remote command in order to hide peeled tags and pseudorefs like HEAD from output. Otherwise the action fails when trying to delete annotated tags as they appear in the form of vX.X.X^{} commit 801baf5e03b2973fa7331d3d09bbd0d792154efd Merge: df0035d be5626b Author: Siavash Safi Date: Wed Jul 22 09:53:02 2020 +0200 Merge pull request #5 from teivah/master Adding a mechanism to filter per prefix commit be5626baea4205ee23e07c1e66ab332189f8b2a5 Author: teivah Date: Wed Jul 22 09:44:24 2020 +0200 Adding a mechanism to filter per prefix commit df0035d0cdc7fdf9f7304e811aa3efb40841c81a Merge: d7a53d7 56f53d0 Author: Markos Chandras Date: Tue Jun 16 08:23:51 2020 +0100 Merge pull request #4 from beatlabs/fix-tag-deletion Fix bug when deleting branches with delete_tags=true commit 56f53d0fefce37e0133cc8df61a774926a98134d Author: Markos Chandras Date: Mon Jun 15 14:28:57 2020 +0100 Fix bug when deleting branches with delete_tags=true Fix a bug where a branch deletion will fail with 422 whene delete_tags is true. This is because the logic was broken and the wrong endpoint was used to delete the object. commit d7a53d7e49dc0c43ce394cd451101e40eced54a8 Merge: dbfa3f3 0698a3a Author: Markos Chandras Date: Mon Jun 15 08:38:42 2020 +0100 Merge pull request #3 from beatlabs/enhance-debug-log delete-old-brances: Add option to dump the curl output on failures commit 0698a3a87a9526d4de033477c373f11009d1bff2 Author: Markos Chandras Date: Fri Jun 12 10:36:47 2020 +0100 delete-old-brances: Add option to dump the curl output on failures Redirect output to a debug file which can then dump when the delete request fails commit dbfa3f3c696751980d3b8635184ae7fbecf9968f Merge: 375cfc4 c0cb74b Author: Markos Chandras Date: Thu Jun 4 09:43:10 2020 +0100 Merge pull request #2 from beatlabs/fix-for-tags delete-old-branches: Also fetch tags during initial git fetch commit c0cb74b235125ecca7b1b657bf3d43758bb92d1e Author: Markos Chandras Date: Thu Jun 4 09:07:12 2020 +0100 Also fetch tags during initial git fetch We need to have the tags present on the repo to be able to examine their history This also updates the release action to the latest commit to fix an issue with commit filtering. commit 375cfc41eff88d057abc188a967979f5ca9802fe Merge: 75a26c7 3fe627f Author: Markos Chandras Date: Thu Jun 4 09:01:31 2020 +0100 Merge pull request #1 from beatlabs/add-tag-support Add support for deleting old tags as well commit 3fe627f2fabada3f792a6ac38975b821fe79e175 Author: Markos Chandras Date: Wed Jun 3 10:58:39 2020 +0100 Add support for deleting old tags as well It might also be beneficial to get rid of old tags so add a new `delete_tags` option for that which defaults to `false` to preserve the existing behavior. commit 75a26c7797342be0150f381b4b468e0668ab7645 Author: Markos Chandras Date: Fri May 22 14:36:18 2020 +0100 README: Delete Release badge The badge only makes sense for tags so no point in having it in the README file. --- README.md | 2 ++ action.yml | 30 +++++++++++++++++------------- delete-old-branches | 21 +++++++++++++++++++++ 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7a8b6a2..bb0bd81 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ The default behaviour is to exclude the default branch (main or master) and the Additional branches can be excluded using the `extra_protected_branch_regex` variable (see example below). Similarly, certain tags can be excluded using the `extra_protected_tag_regex` variable. +The default behaviour is to exclude Github protected branches as well as branches with open pull requests. Additional branches can be excluded using the `extra_protected_branch_regex` variable. Branches with open pull requests can be ignored as well (see example below). ## Disclaimer @@ -41,6 +42,7 @@ jobs: minimum_tags: 5 extra_protected_branch_regex: ^(foo|bar)$ extra_protected_tag_regex: '^v.*' + exclude_open_pr_branches: true ``` Once you are happy switch, `dry_run` to `false` so the action actually does the job diff --git a/action.yml b/action.yml index 73fad92..0abb3d3 100644 --- a/action.yml +++ b/action.yml @@ -1,37 +1,41 @@ # action.yml -name: 'Delete old branches' -description: 'Delete branches which are older than certain period of time' -author: 'Markos Chandras' +name: "Delete old branches" +description: "Delete branches which are older than certain period of time" +author: "Markos Chandras" inputs: repo_token: - description: 'The GITHUB_TOKEN secret' + description: "The GITHUB_TOKEN secret" required: true date: - description: 'A git-log compatible date format' + description: "A git-log compatible date format" required: true dry_run: - description: 'Run in dry-run mode so no branches are deleted' + description: "Run in dry-run mode so no branches are deleted" required: false default: true delete_tags: - description: 'Also look for tags to delete' + description: "Also look for tags to delete" required: false default: false minimum_tags: - descritpion: 'Minimum number of tags to keep' + descritpion: "Minimum number of tags to keep" required: false default: false default_branches: - description: 'Default branch(es) to exclude' + description: "Default branch(es) to exclude" required: false default: main,master extra_protected_branch_regex: - description: 'grep extended (ERE) compatible regex for additional branches to exclude' + description: "grep extended (ERE) compatible regex for additional branches to exclude" required: false extra_protected_tag_regex: - description: 'grep extended (ERE) compatible regex for additional tags to exclude' + description: "grep extended (ERE) compatible regex for additional tags to exclude" required: false + exclude_open_pr_branches: + description: "Exclude branches that have an open pull request" + required: false + default: true runs: - using: 'docker' - image: 'Dockerfile' + using: "docker" + image: "Dockerfile" diff --git a/delete-old-branches b/delete-old-branches index 5ebb30c..05614c4 100755 --- a/delete-old-branches +++ b/delete-old-branches @@ -15,6 +15,7 @@ MINIMUM_TAGS=${INPUT_MINIMUM_TAGS:-0} DEFAULT_BRANCHES=${INPUT_DEFAULT_BRANCHES:-main,master} EXCLUDE_BRANCH_REGEX=${INPUT_EXTRA_PROTECTED_BRANCH_REGEX:-^$} EXCLUDE_TAG_REGEX=${INPUT_EXTRA_PROTECTED_TAG_REGEX:-^$} +EXCLUDE_OPEN_PR_BRANCHES=${INPUT_EXCLUDE_OPEN_PR_BRANCHES:-true} default_branch_protected() { local br=${1} @@ -58,6 +59,24 @@ extra_branch_or_tag_protected() { return $? } +is_pr_open_on_branch() { + if [[ "${EXCLUDE_OPEN_PR_BRANCHES}" == false ]]; then + return 1 + fi + + local br=${1} + open_prs_branches=$(curl -X GET -s -H "Authorization: token ${GITHUB_TOKEN}" \ + "${BASE_URI}/repos/${REPO}/pulls" | jq '.[].head.ref' | tr -d '"') + + for pr_br in ${open_prs_branches}; do + if [[ "${pr_br}" == "${br}" ]]; then + return 0 + fi + done + + return 1 +} + delete_branch_or_tag() { local br=${1} ref="${2}" @@ -86,6 +105,8 @@ main() { default_branch_protected "${br}" && echo "branch: ${br} is a default branch. Won't delete it" && continue branch_protected "${br}" && echo "branch: ${br} is likely protected. Won't delete it" && continue extra_branch_or_tag_protected "${br}" "branch" && echo "branch: ${br} is explicitly protected and won't be deleted" && continue + extra_branch_protected "${br}" && echo "branch: ${br} is explicitly protected and won't be deleted" && continue + is_pr_open_on_branch "${br}" && echo "branch: ${br} has an open pull request and won't be deleted" && continue delete_branch_or_tag "${br}" "heads" fi done