{"id":15140359,"url":"https://github.com/tspascoal/whack-a-branch","last_synced_at":"2025-09-29T08:31:56.898Z","repository":{"id":42628081,"uuid":"391157721","full_name":"tspascoal/whack-a-branch","owner":"tspascoal","description":"Play whack-a-mole with branches. As soon as a branch is pushed, if it doesn't meet your naming criteria they will be immediately deleted.","archived":true,"fork":false,"pushed_at":"2022-09-20T15:16:00.000Z","size":396,"stargazers_count":1,"open_issues_count":16,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-15T11:08:25.309Z","etag":null,"topics":["actions","github","probot"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tspascoal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-30T18:24:51.000Z","updated_at":"2023-01-27T21:03:09.000Z","dependencies_parsed_at":"2023-01-18T14:01:35.745Z","dependency_job_id":null,"html_url":"https://github.com/tspascoal/whack-a-branch","commit_stats":{"total_commits":7,"total_committers":2,"mean_commits":3.5,"dds":0.1428571428571429,"last_synced_commit":"5206b0b295edd7216175df92eff17084924d82af"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tspascoal%2Fwhack-a-branch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tspascoal%2Fwhack-a-branch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tspascoal%2Fwhack-a-branch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tspascoal%2Fwhack-a-branch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tspascoal","download_url":"https://codeload.github.com/tspascoal/whack-a-branch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234604487,"owners_count":18859164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actions","github","probot"],"created_at":"2024-09-26T08:02:38.827Z","updated_at":"2025-09-29T08:31:56.458Z","avatar_url":"https://github.com/tspascoal.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# whack-a-branch\n\n\u003e This solution is now considerated deprecated, GitHub can now block creation of [branches out of the box](https://github.blog/changelog/2022-05-05-block-creation-of-branches-that-have-matching-names/)\n\n\u003e A solution to delete branches that do not meet your defined criteria in terms of naming.\n\nIt has two different implementations:\n\n- A [GitHub App](#Application) built with [Probot](https://github.com/probot/probot) this solution works in real time and deletes the branches as soon as they are pushed.\n- A GitHub [action](#Action) to be used in a workflow to delete the branches on an [event](https://docs.github.com/en/actions/reference/events-that-trigger-workflows) of your choice, but most likely on a [scheduled](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events) basis.\n\nYou can specify the (with patterns) the branches that you want to keep and the ones you want to delete.\n\n\u003e **Note:** This is a _sample_ and you should run at your own risk, since deleting branches is a desctructive action that cannot be undone.\n\n## Application\n\n### Setup\n\nIn the `app` directory:\n\n```sh\n# Install dependencies\nnpm install\n\n# Run the bot\nnpm start\n```\n\n### Docker\n\nIn the root directory of the project:\n\n```sh\n# 1. Build container\ndocker build -t whack-a-branch . -f app/Dockerfile\n\n# 2. Start container\ndocker run -e APP_ID=\u003capp-id\u003e -e PRIVATE_KEY=\u003cpem-value\u003e whack-a-branch\n```\n\n### Configuration\n\nBy default, no branch will be deleted, in order to configure the application, you need to create a `.whack-a-branch.yml` file in the `.github` of the project.\n\nThe file should look like this:\n\n```yaml\nonlyNew: true  # default value: false. If true, only new branches will be deleted\ndeleteIfNoMatch: true # default value: false. If true, branches that do not meet the criteria will be deleted\n\n# Patterns are case in-sensitive and can be specified with minimatch expression\nbranches:\n  # The patterns list that defines if the branch will be kept.\n  keep:  # default value \"**\"\n    - '**' # Keep all branches by default\n    - 'dev/**' # Keep all branches in the `dev` folder (redundant with the keep pattern above)\n  # The patterns list that defines if the branch will be deleted.\n  # If there is a conflict between keep and delete, delete will be used.\n  delete:\n    - master\n    - 'delete/**'\n    - 'test*/**'\n```\n\n#### Parameters\n\n##### onlyNew\n\nIf this value is set to true (default value: false), only pushes to new branches will be deleted, existing branches will be kept even if they match a deletion pattern.\n\n##### branches\n\nTo do the matching for patterns you can use [minimatch](https://github.com/isaacs/minimatch) patterns.\n\nThe branch being evaulated will be matched both against the `keep` and `delete` pattern lists.\n\nIf no match is in either of the list, then the branch will be kept or deleted based on the `deleteIfNoMatch` parameter.\n\n\u003e **Note:** Comparisons are case-insensitive.\n\nThe branch being evaluated will match the list of expressions in the `keep` list (order is not relevant) and it will be kept if there is a match, howeve If the branch matches any of the expressions in the `delete` list, it will be deleted (delete always wins).\n\n\u003e Only `heads` are supported, the patterns can either be explicit and define `heads` preffix or omit it. (eg: `head`or `heads/master`)\n\nFor more information about glob patterns, see the [Filter pattern cheat sheet](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet).\n\n#### deleteIfNoMatch\n\nYou can play with the patterns and the `deleteIfNoMatch` option for flexibility, for example if you set this value to `true` you can explicitily set the pattern(s) that you want to keep and anything that doesn't fall into this list will be deleted.\n\n\u003e It is advised to always have `**` in the `keep` list in case `deleteIfNoMatch` is set to `true`.\n\n#### Examples\n\nOnly allow branches with no _folders_ in the name:\n\n```yaml\nbranches:\n  keep:\n    - '*'\n  delete:\n    - '*/**'\n```\n\nOnly allow `main` and `feature` branches in a `dev` folder:\n\n```yaml\ndeleteIfNoMatch: true\nbranches:\n  keep:\n    - 'main'\n  delete:\n    - 'dev/**'\n```\n\nDon't allow people to push `master`:\n\n```yaml\nbranches:\n  delete:\n    - 'master'\n```\n\n### Hosting\n\nThe app is not hosted, only source code is provided. You have to do your own hosting.\n\n## Action\n\n### Usage\n\n```yaml\n- uses: tspascoal/whack-a-branch@v1\n  id: deletebranches\n  with:\n    # list of branches to keep (comma separated list).\n    # Default: \"**\"\n    branches-keep: '**'\n\n    # list of branches to delete (comma separated list).\n    branches-delete:\n    # If true, branches that do not meet the keep/delete criteria(s) will be deleted\n    # default: false\n    delete-if-no-match: 'false'\n\n    # If true, no action deletion will occur\n    # default: false\n    dry-run: 'true'\n    # The separator used to separate the list of deleted branches for the action output.\n    # default value: ','.\n    output-separator: \"\\n\"\n\n    # Token to be used to delete the branches.\n    # Default: ${{ github.token }}\n    token: ''\n\n- run: echo we deleted ${{ steps.deletebranches.outputs.deleted-branches }}\n```\n\nSee the App configuration section for more information about the parameters.\n\n\u003e Protected branches are not deleted, even if they fall within the deletion criteria.\n\n## Contributing\n\nIf you have suggestions for how whack-a-branch could be improved, or want to report a bug, open an issue! We'd love all and any contributions.\n\nFor more, check out the [Contributing Guide](CONTRIBUTING.md).\n\n## License\n\n[ISC](LICENSE) © 2021 Tiago Pascoal \u003ctiago@pascoal.net\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftspascoal%2Fwhack-a-branch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftspascoal%2Fwhack-a-branch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftspascoal%2Fwhack-a-branch/lists"}