Skip to content

Commit e933f68

Browse files
committed
refactor: use ValueTask over Task where appropriate
1 parent 45ccee6 commit e933f68

File tree

5 files changed

+253
-252
lines changed

5 files changed

+253
-252
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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 ValueTask ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action)
2121
{
2222
...
2323
}
@@ -41,22 +41,23 @@ Libraries to handle GitHub Webhooks in .NET applications.
4141
});
4242
```
4343

44-
`MapGitHubWebhooks()` takes two optional parameters:
44+
`MapGitHubWebhooks()` takes three optional parameters:
4545

4646
* `path`. Defaults to `/api/github/webhooks`, the URL of the endpoint to use for GitHub.
4747
* `secret`. The secret you have configured in GitHub, if you have set this up.
48+
* `cancelOnRequestAborted`. Defaults to `false`, indicates whether the processing of the webhook should be cancelled if the request is aborted.
4849

4950
### Azure Functions
5051

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

5657
```C#
5758
public sealed class MyWebhookEventProcessor : WebhookEventProcessor
5859
{
59-
protected override Task ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action, CancellationToken cancellationToken = default)
60+
protected override ValueTask ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action, CancellationToken cancellationToken = default)
6061
{
6162
...
6263
}

samples/AspNetCore/MyWebhookEventProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ 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 ValueTask ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action, CancellationToken cancellationToken = default)
1313
{
1414
switch (action)
1515
{

samples/AzureFunctions/MyWebhookEventProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ 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 ValueTask ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action, CancellationToken cancellationToken = default)
1313
{
1414
switch (action)
1515
{

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)