Skip to content

Commit c16bca8

Browse files
authored
Make webhooks process async (#17)
1 parent 85c9bf0 commit c16bca8

File tree

4 files changed

+435
-673
lines changed

4 files changed

+435
-673
lines changed

Octokit.Webhooks.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
6060
.github\workflows\release-drafter.yml = .github\workflows\release-drafter.yml
6161
EndProjectSection
6262
EndProject
63+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore", "samples\AspNetCore\AspNetCore.csproj", "{2EE1581B-E8B6-409E-8879-6F1EFC8C682B}"
64+
EndProject
65+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{174C8B3B-E8D3-4845-AE7C-8C0DEC43354F}"
66+
EndProject
6367
Global
6468
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6569
Debug|Any CPU = Debug|Any CPU
@@ -78,6 +82,10 @@ Global
7882
{E46C1DB5-F21C-46A9-8D17-F08278BC0BF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
7983
{E46C1DB5-F21C-46A9-8D17-F08278BC0BF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
8084
{E46C1DB5-F21C-46A9-8D17-F08278BC0BF8}.Release|Any CPU.Build.0 = Release|Any CPU
85+
{2EE1581B-E8B6-409E-8879-6F1EFC8C682B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
86+
{2EE1581B-E8B6-409E-8879-6F1EFC8C682B}.Debug|Any CPU.Build.0 = Debug|Any CPU
87+
{2EE1581B-E8B6-409E-8879-6F1EFC8C682B}.Release|Any CPU.ActiveCfg = Release|Any CPU
88+
{2EE1581B-E8B6-409E-8879-6F1EFC8C682B}.Release|Any CPU.Build.0 = Release|Any CPU
8189
EndGlobalSection
8290
GlobalSection(SolutionProperties) = preSolution
8391
HideSolutionNode = FALSE
@@ -89,6 +97,7 @@ Global
8997
{841C67EF-BBB2-4730-8E29-22FF3FD54306} = {EFE1E5ED-D337-4874-82EC-D9FA0BC7D3AB}
9098
{E46C1DB5-F21C-46A9-8D17-F08278BC0BF8} = {719809C2-A551-4C4A-9EFD-B10FB5E35BC0}
9199
{566DF0E2-1288-4083-9B55-4C8B69BB1432} = {EFE1E5ED-D337-4874-82EC-D9FA0BC7D3AB}
100+
{2EE1581B-E8B6-409E-8879-6F1EFC8C682B} = {174C8B3B-E8D3-4845-AE7C-8C0DEC43354F}
92101
EndGlobalSection
93102
GlobalSection(ExtensibilityGlobals) = postSolution
94103
SolutionGuid = {73F36209-F8D6-4066-8951-D97729F773CF}

samples/AspNetCore/MyWebhookEventProcessor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace AspNetCore
22
{
3+
using System.Threading.Tasks;
34
using Microsoft.Extensions.Logging;
45
using Octokit.Webhooks;
56
using Octokit.Webhooks.Events;
@@ -14,15 +15,17 @@ public MyWebhookEventProcessor(ILogger<MyWebhookEventProcessor> logger)
1415
this.logger = logger;
1516
}
1617

17-
protected override void ProcessPullRequestWebhook(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action)
18+
protected override async Task ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action)
1819
{
1920
switch (action)
2021
{
2122
case PullRequestActionValue.Opened:
2223
this.logger.LogInformation("pull request opened");
24+
await Task.Delay(1000);
2325
break;
2426
default:
2527
this.logger.LogInformation("Some other pull request event");
28+
await Task.Delay(1000);
2629
break;
2730
}
2831
}

src/Octokit.Webhooks.AspNetCore/GitHubWebhookExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public static void MapGitHubWebhooks(this IEndpointRouteBuilder endpoints, strin
3636
try
3737
{
3838
var service = context.RequestServices.GetRequiredService<WebhookEventProcessor>();
39-
service.ProcessWebhook(context.Request.Headers, body);
39+
await service.ProcessWebhookAsync(context.Request.Headers, body)
40+
.ConfigureAwait(false);
4041
context.Response.StatusCode = 200;
4142
}
4243
catch (Exception)

0 commit comments

Comments
 (0)