Skip to content

Commit bb254a2

Browse files
committed
Pass CancellationToken to WebhookEventProcessor by default
1 parent aea11ce commit bb254a2

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ Libraries to handle GitHub Webhooks in .NET applications.
1717
```C#
1818
public sealed class MyWebhookEventProcessor : WebhookEventProcessor
1919
{
20-
protected override Task ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action)
20+
protected override Task ProcessPullRequestWebhookAsync(
21+
WebhookHeaders headers,
22+
PullRequestEvent pullRequestEvent,
23+
PullRequestAction action,
24+
CancellationToken cancellationToken = default)
2125
{
2226
...
2327
}
@@ -48,15 +52,19 @@ Libraries to handle GitHub Webhooks in .NET applications.
4852

4953
### Azure Functions
5054

51-
**NOTE**: Support is only provided for [isolated process Azure Functions](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide).
55+
**NOTE**: Support is only provided for [isolated process Azure Functions](https://learn.microsoft.com/azure/azure-functions/dotnet-isolated-process-guide).
5256
5357
1. `dotnet add package Octokit.Webhooks.AzureFunctions`
5458
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:
5559

5660
```C#
5761
public sealed class MyWebhookEventProcessor : WebhookEventProcessor
5862
{
59-
protected override Task ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action, CancellationToken cancellationToken = default)
63+
protected override Task ProcessPullRequestWebhookAsync(
64+
WebhookHeaders headers,
65+
PullRequestEvent pullRequestEvent,
66+
PullRequestAction action,
67+
CancellationToken cancellationToken = default)
6068
{
6169
...
6270
}

samples/AspNetCore/MyWebhookEventProcessor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ namespace AspNetCore;
99

1010
public class MyWebhookEventProcessor(ILogger<MyWebhookEventProcessor> logger) : WebhookEventProcessor
1111
{
12-
protected override async Task ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action, CancellationToken cancellationToken = default)
12+
protected override async Task ProcessPullRequestWebhookAsync(
13+
WebhookHeaders headers,
14+
PullRequestEvent pullRequestEvent,
15+
PullRequestAction action,
16+
CancellationToken cancellationToken = default)
1317
{
1418
switch (action)
1519
{

samples/AzureFunctions/MyWebhookEventProcessor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ namespace AzureFunctions;
99

1010
public class MyWebhookEventProcessor(ILogger<MyWebhookEventProcessor> logger) : WebhookEventProcessor
1111
{
12-
protected override async Task ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action, CancellationToken cancellationToken = default)
12+
protected override async Task ProcessPullRequestWebhookAsync(
13+
WebhookHeaders headers,
14+
PullRequestEvent pullRequestEvent,
15+
PullRequestAction action,
16+
CancellationToken cancellationToken = default)
1317
{
1418
switch (action)
1519
{

src/Octokit.Webhooks.AspNetCore/GitHubWebhookExtensions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ public static partial class GitHubWebhookExtensions
2424
public static IEndpointConventionBuilder MapGitHubWebhooks(
2525
this IEndpointRouteBuilder endpoints,
2626
string path = "/api/github/webhooks",
27-
string? secret = null,
28-
bool cancelOnRequestAborted = false)
27+
string? secret = null)
2928
{
3029
var options = endpoints.ServiceProvider.GetService<IOptionsMonitor<GitHubWebhookOptions>>();
3130
return endpoints.MapPost(
@@ -60,7 +59,7 @@ public static IEndpointConventionBuilder MapGitHubWebhooks(
6059
try
6160
{
6261
var service = context.RequestServices.GetRequiredService<WebhookEventProcessor>();
63-
await service.ProcessWebhookAsync(context.Request.Headers, body, cancelOnRequestAborted ? context.RequestAborted : CancellationToken.None)
62+
await service.ProcessWebhookAsync(context.Request.Headers, body, context.RequestAborted)
6463
.ConfigureAwait(false);
6564
context.Response.StatusCode = 200;
6665
}

src/Octokit.Webhooks.AzureFunctions/GitHubWebhooksHttpFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public sealed partial class GitHubWebhooksHttpFunction(IOptions<GitHubWebhooksOp
5353
kv => kv.Key,
5454
kv => new StringValues([.. kv.Value]),
5555
StringComparer.OrdinalIgnoreCase);
56-
await service.ProcessWebhookAsync(headers, body)
56+
await service.ProcessWebhookAsync(headers, body, ctx.CancellationToken)
5757
.ConfigureAwait(false);
5858
return req.CreateResponse(HttpStatusCode.OK);
5959
}

0 commit comments

Comments
 (0)