Coder Social home page Coder Social logo

afrocandy / branch-protection Goto Github PK

View Code? Open in Web Editor NEW

This project forked from venh/branch-protection

0.0 0.0 0.0 20 KB

Custom GitHub Action to apply / remove Branch Protection Rules to specified branches of repositories within a GitHub Organization

JavaScript 100.00%

branch-protection's Introduction

Set / Delete Branch Protection

This action will set / delete Branch Protection rules on specified branches of GitHub Repositories within an organization. This action, when included in a workflow will help automate the branch protection rules consistently across all the repositories within an organization. Same rules will get applied on the specified branches for all the GitHub Repositories of an organization. The Rules JSON (format provided below in the inputs) should have the branches and rules as key value pairs. The below JSON sample specifies the rules for Main and Release branches. The token used below should be of an Admin user. This action is written using pure JavaScript and Node and hence will work on any runner.

Note: Use this action after the Checkout step in your workflow, since we are specifying the paths of rules JSON and other files and we have to make sure the files are available for use by this action. Hence it is recommended to use this action after the Checkout step. This will remove the existing rules and set the rules based on the JSON. Even for newly provisioned repositories, you can use this action in a workflow with some schedule to consistently apply branch protection rules without any manual intervention.

Inputs

token

Required
Description - This should be the token of a GitHub Admin / Organization Owner to be able to manage all repos within the organization, passed as a secret.

org

Required
Description - Name of your GitHub Organization.

rulesPath

Required
Description - The path of the Rules JSON file with Branch name as Key and Rules as Value. Format of the file is given below. The below JSON applies branch protection rules to release and main branches of a repo.

{ 
    "release" : {
    "restrictions": {
                        "users": [""],
                        "teams": [""]
                    },                              
    "required_status_checks": null,
    "enforce_admins": true,
    "required_linear_history": true,
    "required_pull_request_reviews": {
      "dismiss_stale_reviews": true
    }
  },
  "main": {
    "restrictions":null,                              
    "required_status_checks": null,
    "enforce_admins": null,
    "required_linear_history": null,
    "required_pull_request_reviews": {
      "dismiss_stale_reviews": true
    }
  }
}

includedReposPath

Description - Path of the text file (.txt) with only those repos on which the branch protection needs to be applied. Specify every repo name (without org/ prefix) on a new line. This is optional. If not provided, branch protection will be set on all the repos within the organization.

excludedReposPath

Description - Path of the text file(.txt) with repos to be excluded from branch protection. Specify every repo name (without org/ prefix) on a new line. This is optional. If not provided, no repos will be excluded and branch protection will be applied on all the repos within the organization.

action

Description - This GitHub Custom action can be used to set / add / delete branch protection. The default value is set (if not specified). If add is assigned, it will add branch protection to every repo, if branch protection is not applied. If delete is assigned, it will remove branch protection from every repo, if branch protection is already applied. Default - 'set'

Usage


- name: Run Branch Protection
  uses: venh/[email protected]
  with:
    token: '${{ secrets.GITHUB_ADMIN_ACCESS_TOKEN }}' 
    org: Name-Of-Your-GitHub-Organization 
    rulesPath: ./rules.json 
    includedReposPath: ./includedRepos.txt
    excludedReposPath: ./excludedRepos.txt
    action: set

License

This project is released under the MIT License

branch-protection's People

Contributors

venh avatar afrocandy avatar

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.