Skip to content

Commit

Permalink
Make webhooks process async (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marethyu1 authored Nov 23, 2021
1 parent 85c9bf0 commit c16bca8
Show file tree
Hide file tree
Showing 4 changed files with 435 additions and 673 deletions.
9 changes: 9 additions & 0 deletions Octokit.Webhooks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\release-drafter.yml = .github\workflows\release-drafter.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCore", "samples\AspNetCore\AspNetCore.csproj", "{2EE1581B-E8B6-409E-8879-6F1EFC8C682B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{174C8B3B-E8D3-4845-AE7C-8C0DEC43354F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -78,6 +82,10 @@ Global
{E46C1DB5-F21C-46A9-8D17-F08278BC0BF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E46C1DB5-F21C-46A9-8D17-F08278BC0BF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E46C1DB5-F21C-46A9-8D17-F08278BC0BF8}.Release|Any CPU.Build.0 = Release|Any CPU
{2EE1581B-E8B6-409E-8879-6F1EFC8C682B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2EE1581B-E8B6-409E-8879-6F1EFC8C682B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EE1581B-E8B6-409E-8879-6F1EFC8C682B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EE1581B-E8B6-409E-8879-6F1EFC8C682B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -89,6 +97,7 @@ Global
{841C67EF-BBB2-4730-8E29-22FF3FD54306} = {EFE1E5ED-D337-4874-82EC-D9FA0BC7D3AB}
{E46C1DB5-F21C-46A9-8D17-F08278BC0BF8} = {719809C2-A551-4C4A-9EFD-B10FB5E35BC0}
{566DF0E2-1288-4083-9B55-4C8B69BB1432} = {EFE1E5ED-D337-4874-82EC-D9FA0BC7D3AB}
{2EE1581B-E8B6-409E-8879-6F1EFC8C682B} = {174C8B3B-E8D3-4845-AE7C-8C0DEC43354F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {73F36209-F8D6-4066-8951-D97729F773CF}
Expand Down
5 changes: 4 additions & 1 deletion samples/AspNetCore/MyWebhookEventProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AspNetCore
{
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Octokit.Webhooks;
using Octokit.Webhooks.Events;
Expand All @@ -14,15 +15,17 @@ public MyWebhookEventProcessor(ILogger<MyWebhookEventProcessor> logger)
this.logger = logger;
}

protected override void ProcessPullRequestWebhook(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action)
protected override async Task ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestEvent pullRequestEvent, PullRequestAction action)
{
switch (action)
{
case PullRequestActionValue.Opened:
this.logger.LogInformation("pull request opened");
await Task.Delay(1000);
break;
default:
this.logger.LogInformation("Some other pull request event");
await Task.Delay(1000);
break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Octokit.Webhooks.AspNetCore/GitHubWebhookExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public static void MapGitHubWebhooks(this IEndpointRouteBuilder endpoints, strin
try
{
var service = context.RequestServices.GetRequiredService<WebhookEventProcessor>();
service.ProcessWebhook(context.Request.Headers, body);
await service.ProcessWebhookAsync(context.Request.Headers, body)
.ConfigureAwait(false);
context.Response.StatusCode = 200;
}
catch (Exception)
Expand Down
Loading

0 comments on commit c16bca8

Please sign in to comment.