/webhooks.net

GitHub webhook events toolset for .NET

Primary LanguageC#MIT LicenseMIT

Octokit.Webhooks

GitHub Workflow Status Octokit.Webhooks NuGet Package Version Octokit.Webhooks NuGet Package Downloads

Libraries to handle GitHub Webhooks in .NET applications.

Usage in ASP.NET Core

  1. dotnet add package Octokit.Webhooks.AspNetCore

  2. Create a class that derives from WebhookEventProcessor and override any of the virtual methods to handle webhooks from GitHub. For example, to handle Pull Request webhooks:

    public sealed class MyWebhookEventProcessor : WebhookEventProcessor
    {
        protected override void ProcessPullRequestWebhook(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action) {
            ...
        }
    }
  3. Modify your ConfigureServices() method to register an implementation for GitHubEventProcessor:

    public void ConfigureServices(IServiceCollection services)
    {
        ...
        services.AddSingleton<WebhookEventProcessor, MyWebhookEventProcessor>();
        ...
    }
  4. Modify your Configure() method to map the webhook end point:

    app.UseEndpoints(endpoints =>
    {
        ...
        endpoints.MapGitHubWebhooks();
        ...
    });

MapGitHubWebhooks() takes two optional parameters:

  • path. Defaults to /api/github/webhooks, the URL of the endpoint to use for GitHub.
  • secret. The secret you have configured in GitHub, if you have set this up.

Thanks

License

All packages in this repository are licensed under the MIT license.