Skip to content

GitHub webhook events toolset for .NET

License

Notifications You must be signed in to change notification settings

ownerrez/webhooks.net

This branch is 12 commits behind octokit/webhooks.net:main.

Folders and files

NameName
Last commit message
Last commit date
Nov 20, 2024
Feb 26, 2025
Nov 14, 2023
Sep 11, 2021
Feb 25, 2025
Feb 13, 2025
Feb 20, 2025
Aug 9, 2022
Sep 7, 2021
Sep 14, 2021
Sep 21, 2021
Sep 27, 2021
Feb 13, 2025
Apr 6, 2023
Aug 27, 2021
Sep 21, 2021
Oct 8, 2024
Oct 8, 2024
Jun 16, 2022
Jun 13, 2022
Nov 13, 2024
Feb 13, 2025
Jul 3, 2022

Repository files navigation

Octokit.Webhooks

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

Libraries to handle GitHub Webhooks in .NET applications.

Usage

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 Task ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action) 
        {
            ...
        }
    }
  3. Register your implementation of WebhookEventProcessor:

    builder.Services.AddSingleton<WebhookEventProcessor, MyWebhookEventProcessor>();
  4. Map the webhook endpoint:

    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.

Azure Functions

NOTE: Support is only provided for isolated process Azure Functions.

  1. dotnet add package Octokit.Webhooks.AzureFunctions

  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 Task ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action) 
        {
            ...
        }
    }
  3. Register your implementation of WebhookEventProcessor:

    .ConfigureServices(collection =>
    {
        ...
        collection.AddSingleton<WebhookEventProcessor, MyWebhookEventProcessor>();
        ...
    })
  4. Configure the webhook function:

    new HostBuilder()
    ...
    .ConfigureGitHubWebhooks()
    ...
    .Build();

ConfigureGitHubWebhooks() either takes an optional parameter:

  • secret. The secret you have configured in GitHub, if you have set this up.

or:

  • configure. A function that takes an IConfiguration instance and expects the secret you have configured in GitHub in return.

The function is available on the /api/github/webhooks endpoint.

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

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%