Skip to content

GitHub webhook events toolset for .NET

License

Notifications You must be signed in to change notification settings

drdk/webhooks.net

 
 

Repository files navigation

Octokit.Webhooks

GitHub Workflow Status Octokit.Webhooks NuGet Package Version Octokit.Webhooks NuGet Package Downloads Stability - Experimental

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.

About

GitHub webhook events toolset for .NET

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%