Coder Social home page Coder Social logo

absolutelynothingtoseehere / branch-dictator Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 1.1 MB

Branch Protection via autocratic automation ๐Ÿ‘‘

License: MIT License

JavaScript 7.27% TypeScript 92.73%
branch-protection github-api expressjs octokit jest heroku lgtm codecov

branch-dictator's Introduction

codecov Total alerts Language grade: JavaScript

Branch Dictator ๐Ÿ‘‘

Oh, you thought this was a democracy? Guess again... in this kingdom, branches are micromanaged and admins have less power ยฏ\_(ใƒ„)_/ยฏ

Branch Dictator will enable Branch Protection for all new org repos that are created with public visibility and are created with an initial branch (via the addition of a README.md, LICENSE, and/or .gitignore when the repo is created).

Setup

Interested in using Branch Dictator to keep your kingdom in line? Let's get started.

Fork this Repo

The first step to setting up your own instance of Branch Dictator is to fork this repo. It's designed to be used within an org, so make sure to fork this repo into an org, not under a personal account. If you don't have an org, you can create one for free!

CI/CD

This app uses GitHub Secrets in conjunction with GitHub Actions to perform all CI and CD actions. After forking into your org, head over to your app's Secrets and set the following values:

CODECOV_API_KEY

This project uses Codecov for coverage analysis. Navigate to codecov.io and follow the steps to link your org and repo. When you're done, you'll be provided with an API key.

Heroku

This app uses a GitHub Action to deploy to Heroku; if you'd prefer to use your own hosting solution, make sure to remove that action and ignore the following sections. If you'd like to use Heroku, make sure to create an account before continuing if you don't already have one.

HEROKU_API_KEY

Create a new Heroku Authorization with a description of Branch Dictator API Key or something similar, leave Expires after (seconds) blank, and hit Create.

HEROKU_APP_NAME

Choose a name for your app in Heroku. This name must be unique across all of Heroku, so make sure to use something like your GitHub org name to make it unique (e.g., some-org-branch-dictator).

HEROKU_EMAIL

The email account associated with your Heroku account. This can be found in your Heroku Account Settings.

Environment Variables

This app has a handful of environment variables. The instructions below are for Heroku, but other cloud environments will have a similar method of setting them.

Eventually these values will be stored within the repo's secrets, but for now you'll need to set them manually. After creating your app, navigate to your app's Settings tab, scroll to Config Vars and set the following values:

GITHUB_TOKEN

Create a Personal Access Token with a note of Branch Dictator (or something else of your choice) and enable just the repo scope (NOTE: when selecting repo, all the children of the repo scope will automatically be enabled) and click Generate token.

WEBHOOK_SECRET

This will be used within the Configuring the Webhook section below, but can be whatever text you'd like (just make sure it's not blank!).

NODE_ENV

Set this value to production to ensure the app behaves as expected and will not start if certain required variables are not present.

LGTM

This project also uses LGTM for codescanning. If you'd like to use LGTM within your project, create an account and follow the steps to link your repo and install the LGTM app within your org.

Configuring the Webhook

Once your app is deployed and ready to go, you'll need to create a webhook to ensure the app is notified when repos are created. Head to your org's settings page and navigate to the Webhooks section. Click Add webhook and use the following values:

  • Payload URL: {your-app's-URL}/api/webhook/repository} (e.g., https://my-branch-dictator/api/webhook/repository)
  • Content type: application/json
  • Secret: Your secret from the WEBHOOK_SECRET section above
  • SSL verification: โœ… Enable SSL Verification
  • Which events would you like to trigger this webhook?: Let me select individual events - uncheck all except:
    • Repositories
  • Active: โœ…

Click Add webhook and wait for the response from your app. If you see anything but a 200 status code on the response, make sure to click back into the webhook settings, scroll down, and click on the Response tab to see more info. If you see a 200, you're all set! To make sure things are working, create a new public repo with a README and then check the repo's branch protection settings and validate that an issue was creted notifying you of the change to the settings.

Development

Environment Variables

Project environment variables should first be defined in .env.sample without real values for their data (that file is tracked by git). After cloning, make sure to duplicate .env.sample as .env and then fill in all required variables.

Dependencies

This project is reliant on the installation of the following dependencies:

After downlodaing the dependencies above, install all NPM dependencies by running npm i.

Starting the App

The best way to start the app and work on it is by using npm run dev, which will start the app and then restart the app whenever a TypeScript file changes. After modifying a non-Typescript file, restart the app by typing rs into the same terminal you ran npm run dev from and then hitting return.

After the app starts, it will be accessible on localhost:3000 (unless the port was modified via .env).

branch-dictator's People

Contributors

spencerkaiser avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

lgtm-migrator

branch-dictator's Issues

bug(branchless repo): Repo creation without branch results in 500

Pre-requisites:

Description

Creating a repo without a README, license, and gitignore results in a branchless repo which in turn results in a 500 error due to an api 404 (branch doesn't exist)

Expected Behavior

The app should know not to try to hit the API

Actual Behavior

A 404 -> 500

Repro Steps

Create a repo without creating an initial commit

Other Information

I'd argue that this is a bug on the GitHub side of things... if a repo doesn't have a branch, the default_branch should be null. I'm not actually sure if a repo in GitHub can have a branch. If the repo truly does have a branch, specifying the latest commit (or even updating pushed_at to have a value on repo creation) would give the recipient of the event a little more context.

feat(GitHub Actions): Create CI/CD actions

Pre-requisites:

Feature Description

The project should have Actions to support CI and CD with the following features:

CI (required for PR merge)

  • Build the app
  • Run test suite
  • Run linter
  • Run prettier

Status should be reported back and a badge should display said status in the README

CD (on merge to master)

  • Deploy the app to Heroku

Additional Details

feature(Heroku env variables): Store env variables in GitHub and use in the Heroku Action

Pre-requisites:

Feature Description

Ideally all environment variables used in Heroku would exist in the repo's secrets and used on deploy to maintain 100% uptime and prevent the need for manually setting environment variables.

Additional Details

Hold: This issue against the Heroku Deploy Action must be implemented before this issue can be addressed.

feat(org even listener): Implement event listener for

Pre-requisites:

Feature Description

The app should include a event listener for the repository event. The listener should validate the event and use the webhook secret to ensure the authenticity of the request. If the request is unauthorized, return an appropriate status code, otherwise return a 200.

Additional Details

The webhook's actual implementation will be covered by another issue.

feat(middleware): Utilize utilize @octokit/webhooks

Pre-requisites:

Feature Description

It would be super convenient to use @octokit/webhooks's middleware functionality, unfortunately the index.d.ts file seems to be missing some exports for the standalone functionality. Without creating our own declaration file (which would be brittle), custom implementation seems like the best approach.

Additional Details

hold: I opened an issue against the project, so after that is fixed this can be implemented

feature(private repos): Enable private repo branch protection

Pre-requisites:

Feature Description

The GitHub API requires users to have a Pro account or for the repo privacy to be public:

Upgrade to GitHub Pro or make this repository public to enable this feature. - Upgrade to GitHub Pro or make this repository public to enable this feature.

If the user has a Pro account, they should be able to set an environment variable to allow for private repo branch protection and override the existing check.

Additional Details

bug(private repo): Private repo creation results in a 500

Pre-requisites:

Description

Creating a private repo results in a 500

Expected Behavior

The app should skip the call to the GitHub api as it will always fail

Actual Behavior

It calls the api, fails, and throws a 500

Repro Steps

Create a private repo

Other Information

bug(auth failure): Webhook events throw 401

Pre-requisites:

Description

Events are currently failing with a 401

Expected Behavior

They'd pass with a 200

Actual Behavior

401

Repro Steps

Trigger a webhook event

Other Information

Turns out the x-hub-signature actually has sha1= prepended to it; the validation logic needs to be updated to add that.

feat(lgtm): Enable lgtm

Pre-requisites:

Feature Description

This project should utilize lgtm for code analysis and PRs should be dependent on successful passing of their tests

Additional Details

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.