https://github.com/octokit/webhooks.net
GitHub webhook events toolset for .NET
https://github.com/octokit/webhooks.net
github-api github-webhook github-webhooks hacktoberfest octokit octokit-net sdk webhooks
Last synced: 11 days ago
JSON representation
GitHub webhook events toolset for .NET
- Host: GitHub
- URL: https://github.com/octokit/webhooks.net
- Owner: octokit
- License: mit
- Created: 2021-08-27T11:34:49.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-06-11T13:46:16.000Z (17 days ago)
- Last Synced: 2025-06-11T14:56:27.268Z (17 days ago)
- Topics: github-api, github-webhook, github-webhooks, hacktoberfest, octokit, octokit-net, sdk, webhooks
- Language: C#
- Homepage:
- Size: 1.85 MB
- Stars: 58
- Watchers: 9
- Forks: 36
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Octokit.Webhooks
[](https://github.com/octokit/webhooks.net/actions/workflows/build.yml?query=branch%3Amain)
[](https://www.nuget.org/packages/Octokit.Webhooks/)
[](https://www.nuget.org/packages/Octokit.Webhooks/)
[](https://scorecard.dev/viewer/?uri=github.com/octokit/webhooks.net)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:```C#
public sealed class MyWebhookEventProcessor : WebhookEventProcessor
{
protected override Task ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action)
{
...
}
}
```3. Register your implementation of `WebhookEventProcessor`:
```C#
builder.Services.AddSingleton();
```4. Map the webhook endpoint:
```C#
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](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide).
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:```C#
public sealed class MyWebhookEventProcessor : WebhookEventProcessor
{
protected override Task ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action)
{
...
}
}
```3. Register your implementation of `WebhookEventProcessor`:
```C#
.ConfigureServices(collection =>
{
...
collection.AddSingleton();
...
})
```4. Configure the webhook function:
```C#
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
- [octokit/webhooks](https://github.com/octokit/webhooks)
- [terrajobst/Terrajobst.GitHubEvents](https://github.com/terrajobst/Terrajobst.GitHubEvents)
- [Dotnet-Boxed/Templates](https://github.com/Dotnet-Boxed/Templates)## License
All packages in this repository are licensed under [the MIT license](https://opensource.org/licenses/MIT).