GithubHelp home page GithubHelp logo

svanboxel / delete-merged-branch Goto Github PK

View Code? Open in Web Editor NEW
318.0 11.0 57.0 2.62 MB

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

Home Page: https://github.com/apps/delete-merged-branch/

License: ISC License

JavaScript 97.65% Shell 2.35%
probot

delete-merged-branch's Introduction

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

delete-merged-branch's People

Contributors

cyberhck avatar dependabot[bot] avatar ezhlobo avatar graham42 avatar greenkeeper[bot] avatar localheinz avatar seeplusplus avatar svanboxel avatar tknickman avatar zangbe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

delete-merged-branch's Issues

This appears to have stopped working on our org repos

Hi - I have deleted and reinstalled the bot but it is no longer deleted merged branches. Is there anything else I should try. Does it work OK if someone has enabled the Github setting to do the same. I prefer the bot since it's easier to enable at org level. Thanks!

Github Teams Support

Hi,

We would like to adopt this app for our org (I used it at my old place and it was awesome) but do not want it across every repo.

Please add a way to limit it to a teams repos only.

Thanks!

master branch getting deleted

Since installing this plugin, we've been having issues with our master branches getting deleted.

Example Scenario:

  1. Repository has its default branch set to master.
  2. User1 makes a PR from their fork (User1 wants to merge 1 commit into OrgName:master from User1:master).
  3. PR gets merged.
  4. OrgName:master branch is deleted and the default branch is set to one of the other branches on the repository.

Our testing indicates that this issue does not occur if the PR is from a non-master fork branch (User1 wants to merge 1 commit into OrgName:master from User1:NewFeatureBranch).

[feature-request] ability to delay deletion

Would be awesome to be able to delay deletion of a branch.

Use case: Sometimes Iโ€™m working on a feature branch and it gets approved and merged. Later, a bug gets noticed and I go to pull the latest copy of that branch as it was right before merge (to handle cases, for instance, if there had been edits before approval on remote only, or to avoid pulling from master where there may potentially be new commits), though this typically would only be within a set period of time (ie. maybe typically within the first 7 days after initial merge)

Would be nice to account for scenarios like this and be able to access the branch without having to restore first, but still have it auto deleted after a set period of time

Also, thanks a ton as-is for this @SvanBoxel def a fan!

Also, would most definitely be more than happy to help and can most def queue up circling back around here!

Deprecated error object key

07:29:55.916Z  INFO probot: Loaded delete-merged-branch GitHub Application
Deprecation: [@octokit/request-error] `error.code` is deprecated, use `error.status`.
    at RequestError.get (/home/runner/work/_actions/SvanBoxel/delete-merged-branch/main/dist/index.js:15092:17)
    at Object.Logger.stdSerializers.err (/home/runner/work/_actions/SvanBoxel/delete-merged-branch/main/dist/index.js:2735[6](https://github.com/tokenx-finance/tkx-oracle-service/runs/8151391728?check_suite_focus=true#step:2:7):19)
    at mkRecord (/home/runner/work/_actions/SvanBoxel/delete-merged-branch/main/dist/index.js:2[7](https://github.com/tokenx-finance/tkx-oracle-service/runs/8151391728?check_suite_focus=true#step:2:8)150:35)
    at Logger.warn (/home/runner/work/_actions/SvanBoxel/delete-merged-branch/main/dist/index.js:27252:1[9](https://github.com/tokenx-finance/tkx-oracle-service/runs/8151391728?check_suite_focus=true#step:2:10))
    at module.exports (/home/runner/work/_actions/SvanBoxel/delete-merged-branch/main/dist/index.js:64:17)

feature request: auto docker push

Hi there,
I love your deployment process, I want to deploy your app in docker, I'd love if you could publish docker automatically.

I also use semantic-release for versioning, now.sh as lambda function, but in semantic-release, I also push my image to docker hub. Here's a sample: https://github.com/fossapps/MergeWhenReady

It'd be amazing if you could push to docker hub, and I'd just use the app by setting some env variable like so:

APP_ID=""
WEBHOOK_SECRET=""
BASE64_PRIVATE_KEY=""
GHE_HOST="github.private-domain.com"

Thanks, I'd be willing to help you out with this.

Automatically deploy new versions to now

Is your feature request related to a problem? Please describe.
At the moment new versions of this app are manually deployed to Now. This should happen automatically on every release.

Describe the solution you'd like
Make the deploy process part of CI.

Upgrade Action to use node 16 instead of node 12

Following the recent blog post "GitHub Actions: All Actions will begin running on Node16 instead of Node12" by GitHub, I noticed this action is still running on node12:

action.yml

runs:
  using: 'node12'
  main: 'dist/index.js'

This is the warning I see every time I my workflow:

Node.js 12 actions are deprecated. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Please update the following actions to use Node.js 16: SvanBoxel/[email protected]

Not working in github action

I am trying to implement this using github action but its not working.
workflow action keeps on running with progress status neither fails nor succeeds

My action template:

name: Delete Merged Branches

on: [pull_request]

jobs:
  delete:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          # Make sure the actual branch is checked out when running on pull requests
          ref: ${{ github.head_ref }}

      - name: Delete merged branch
        uses: SvanBoxel/[email protected]
        with:
          exclude: staging
          delete_closed_pr: false
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Consider publishing as npm module

To use this github app with @probot/serverless-lambda or @probot/serverless-gcf would be useful to have this app available as an npm package. Then can do something like

const serverless = require('@probot/serverless-lambda')
const appFn = require('delete-merged-branch')
module.exports.probot = serverless(appFn)

Would you consider publishing this as an npm module?

Automatic change of base branch does not work

Hey,

I am faced with following use case, where 3 PRs exist, PR number 2 is being merged, and consequently branchC is being removed:

  1. branchB -> branchA
  2. branchC -> branchB
  3. branchD -> branchC

The behavior of delete-merged-branch integration is slightly different compared to the native Automatically delete head branches repository option:

  • integration: branchC is removed, PR number 3 shows a message that This branch has conflicts that must be resolved and manual change of base branch is required

  • native: branchC is also removed, however base branch in PR number 3 is automatically changed with the following message shown Base automatically changed from branchC to branchB

Is there an option to make the integration work the same as the native one?

Only delete on certain base branches

We can currently exclude based on the head branch of a PR. We want to be able to choose to only delete head on branches that are merged to a given base branch. An example would be the following

on_base:
  - main
  - qa

This would act as a whitelist, so if a PR targets dev, it would not cause the source branch to be deleted.

I'm working on adding this now, just opening the issue to have a number.

feat: delete except specific branches

hi. Thank you for making a good bot. I'm using it well.

However, there is a function that I need. I am running a branch called develop, master, and a release unit distribution branchs. even if these branches are merged, they must not be deleted. Is there a device that can add a branch that shouldn't be deleted?

This feature already exists

Hello amigos,

Im just wondering if is necessary to continue working on this project if this feature already exists :/ You can find it on repository configuration

Screen Shot 2019-11-24 at 01 15 40

Probably this action could be better if you offer more features that github currently gives

[doc request] Now configuration

Hi, I'm a big fan of your probot bot and currently using it in several of my work projects, and I'm trying to actually build one for my own, and was wondering if you could share the now.json file.

In other words, I'm trying to build my own but a bit more custom.

Here is the use case.
We currently have a Jenkins instance that is an internal application but we store the code in Github, so ideally the probot will listen to any pull_request.* and then publish that information to a sns topic which then Lambda will listen to that SNS and then send it to the Jenkins API with the right keys

Yes, its a bit convoluted but its a regular use case that I have seen in many places, and now usually most people just do git pulls every X minutes instead of having a "listen mechanism".

I have part of it done, but your use of now made it for me easier that it can be configured per client since there is the configuration of the sns topic / keys that are specific to each client

Finalizing, can you share the now.json file? From what I can see travis will kind of create it for you , but I might be wrong.

Any help is appreciated!

[bug] GitHub Action hanging

The github action doesn't appear to work. I've cancelled a couple of tasks after 15min of activity and the logs show the following after getting everything setup

...
Already have image (with digest): gcr.io/github-actions-images/action-runner:latest
14:35:13.811Z  INFO probot: Listening on http://localhost:3000
14:35:13.814Z  INFO probot:
  
  Welcome to Probot! Go to http://localhost:3000 to get started.

Exclude branches in Git Actions

Big thanks for the solution. I have a question - how to add excluded branches in Git Actions .yml file?
Is this right?

     env:
         exclude: [development]
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

could this please be expanded to use pull_request_target?

I was hoping to use this in a project, however, we lock down things using pull_request_target for our merges (only delete after after everything is released).

Is there a way to expand this action to also check (or optionally check) for pull_request_target?

The behavior today, is that it will run this action, but no action is taken place and the branch remains.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.