Skip to content

ajaykumarmandapati/delete-merged-branch

 
 

Repository files navigation

delete-merged-branch

Delete merged branch

Build Status Want to see more badges? Click here!

Want to run this app with GitHub Actions? Click here

A GitHub app built with Probot that automatically deletes a branch after it's merged. That's it, enjoy!

🔔 Wait, do you really need this? 🔔

You may not need this app as GitHub recently added this feature natively to their platform. It allows you to automatically delete the head branch after a merge. If you need more advanced controls and configuration settings, this app is still well suited for the job.

Running it locally

  1. First, follow these instructions for making your own GitHub app.

    1. Give your app the following permissions:
      • Repository contents: Read & Write.
      • Pull requests: Read
    2. And Subscribe to the following events
      • Pull Request
  2. Then, clone the repo:

git clone [email protected]:SvanBoxel/delete-merged-branch.git
  1. Copy .env.example to .env and set the right environment variables as here

  2. Now, install app dependencies and run it:

# Install dependencies
npm install

# Run the bot
npm start

How it works

This GitHub app listens to the pull_request.closed webhook. If a pull request is closed and the connected branch is merged, it will delete the branch.

Configuration

The optional app configuration YAML file should be saved as .github/delete-merged-branch-config.yml. At the moment it supports the following options:

  • exclude (array) - list of branches that should not be automatically deleted after a merge. Wildcards supported.
  • delete_closed_pr (bool) whether or not a branch should be deleted if PR is closed without merging

Example .github/delete-merged-branch-config.yml:

exclude: 
  - development
  - qa
  - feature-*
delete_closed_pr: true

Release process

CI (GitHub Actions) is in charge of releasing new versions of the GitHub App to Google Cloud Platform. On every new commit to master we run semantic-release to determine whether the major/minor/patch version should be incremented. If so, we update the version running in production.

Running in GitHub actions

This app is compatible with GitHub Actions. You need to create a workflow that is triggered on the pull_request event for this. Then, you use this repo for the action. (SvanBoxel/delete-merged-branch@master). Don't forget to check the GITHUB_TOKEN secret. That's it.

name: delete branch on close pr
on: 
  pull_request:
    types: [closed]
  
jobs:
  delete-branch:
    runs-on: ubuntu-latest
    steps:
      - name: delete branch
        uses: SvanBoxel/delete-merged-branch@main
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Contributing

If you have suggestions for how this GitHub app could be improved, or want to report a bug, open an issue! We'd love all and any contributions.

For more, check out the Contributing Guide.

License

ISC © 2018 Sebass van Boxel [email protected]

Badges

Build Status codecov Greenkeeper badge Project maintainability npm version Total alerts

About

No more manually deleting merged branches, this lovely app does it for you.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 97.2%
  • Shell 2.8%