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.
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.
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".
After deployment and configuration are complete. We can see the magic work.
-
After a shot delay (whilst the web service acts in the background, refresh the page to see the new issue being notified:
-
Look to the repository settings and click on the branches like to see the protection rules
- 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
Licensed under the MIT License