Libraries to handle GitHub Webhooks in .NET applications.
-
dotnet add package Octokit.Webhooks.AspNetCore -
Create a class that derives from
WebhookEventProcessorand 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) { ... } }
-
Modify your
ConfigureServices()method to register an implementation forGitHubEventProcessor:public void ConfigureServices(IServiceCollection services) { ... services.AddSingleton<WebhookEventProcessor, MyWebhookEventProcessor>(); ... }
-
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.
All packages in this repository are licensed under the MIT license.