Git Product home page Git Product logo

iqbmo04 / github-branch-protector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from marcusfelling/github-branch-protector

0.0 1.0 0.0 911 KB

github-branch-protector is a simple Azure Function (PowerShell Core) that listens for GitHub organization events to know when a repository has been created. When a repo is created, the function automates the protection of the master branch. A notification with an @mention in an issue within the repository outlines the protections that were added.

PowerShell 100.00%

github-branch-protector's Introduction

Overview

github-branch-protector is a simple Azure Function (PowerShell Core) that listens for GitHub organization events to know when a repository has been created. When a repo is created, the function automates the protection of the master branch. A notification with an @mention in an issue within the repository outlines the protections that were added.

Build Status

CI - This is a GitHub action to build and deploy the Function to Azure. See pipeline.yml.

How it works

A function's project directory contains the files host.json and local.settings.json, along with subfolders that contain the code for individual functions. In this project we have 1 function called GitHubEvent trigger. It contains function.json that holds the configuration metadata for the function, and a single script file run.ps1 that contains the function code.

The function is triggered by an HTTP request from a GitHub webhook. When the function is triggered, it then executes run.ps1. Run.ps1 contains the logic to look for a new repository creation from the webhook, if so, invoke GitHub branch API to update master branch's protection, then invoke GitHub issues API to create new issue containing response from adding protection. If event is not creation of new repository, the script does nothing. Upon completion, a response is sent back to the GitHub webhook with the results.

AzureFunctionDiagram.PNG

How to get started

  1. Clone repo to Visual Studio Code workspace
  2. Sign in to Azure using Visual Studio Code
  3. Publish the project to Azure
  4. Add App Settings to Azure Functions:
  • GITHUB_ORGANIZATION: Set the value to name of organization
  • PAT: Create and set value of GitHub personal access token
  • GITHUB_WEBHOOKUSER: Set value to name of user who creates webhook in step 5 below
  1. Create a GitHub webwook in the organization you'd like to protect. When creating the webhook scope it to repository events only. The payload url should be configured to point to the Azure Function trigger url that will look like: https://NAMEOFFUNCTION.azurewebsites.net/api/NAMEOFTRIGGER?code=*******
  2. Create a new repository to test

To Do

github-branch-protector's People

Contributors

marcusfelling avatar

Watchers

James Cloos 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.