Skip to content

A simple web service that listens for GitHub organization events to know when a repository has been created and then protects the main branch automatically.

Notifications You must be signed in to change notification settings

digimangos/octocat-vigilance

Repository files navigation

octocat-vigilance - Main Branch Protection WebService For GitHub

octocat-vigilance is a simple web service that listens for organization events to know when a repository has been created. When a new repository is created the main branch is automatically protected. A new issue is also added to the repository mentioning the account owner of the new protections added. Interactivity with GitHub API is using Octokit.

Getting Started

The first step is determine where the web service will be hosted. From my purposes this is to be deployed directly to Azure App Services, but could equally be deployed in any hosting environment which supports .dotnet core, either via self hosting or IIS. Learning how to get started with App Services and how to configure the azure environment can be found at Quickstart: Deploy an ASP.NET web app.

Once your App Services instance has been configured, you can configure your publish profile to have your development environment deploy directly to Azure. Details can be found on MSDN: Publish an ASP.NET Core app to Azure with Visual Studio.

Once deployed in Azure you are required to configure the settings used by the web service. Inside of Azure portal go to the configuration page for the app service.

There are three settings which need updating:

  • GithubClientSettings__User - Your GitHub username
  • GithubClientSettings__PAT - A Personal access token to give access to the API. This should be created in accordance with the guide Creating a personal access token
  • ApplicationInsights__InstrumentationKey - This is the instrumentation key for your application insights instance as set up using the guide above.

Screen of app service configuration settings

Following configuration of the web service, next you need to configure a GitHub Webhook to point to the url of the app service configured. You can see the base url for the service on the app service overview page. The Webhook is this base url + "GitHubWebhook".

Screenshot of App Service Overview

Screenshot of Github Webhooks configuration

The proof is in the pudding

After deployment and configuration are complete. We can see the magic work.

  • Simply create a new repository Creating a new repository

  • After a shot delay (whilst the web service acts in the background, refresh the page to see the new issue being notified: Issue notification

  • Drill down to the issue, to see the notification message: Issue added

  • Look to the repository settings and click on the branches like to see the protection rules Branch protection rules

References Used

  • GithubWebhook - This nuget package is used for defining the proxy classes sent by Github Webhooks.
  • Octokit.net - This nuget package is used to communicate with the GitHub API, the documentation is referenced from Octokit.net - docs

Copyright and License

Licensed under the MIT License

About

A simple web service that listens for GitHub organization events to know when a repository has been created and then protects the main branch automatically.

Resources

Stars

Watchers

Forks

Languages