Skip to content

Commit b12c341

Browse files
committed
Log webhook errors
1 parent 66415bd commit b12c341

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

src/Web/Webhook.cs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Diagnostics;
22
using System.Globalization;
33
using Microsoft.Extensions.Configuration;
4+
using Microsoft.Extensions.Logging;
45
using Octokit;
56
using Octokit.Webhooks;
67
using Octokit.Webhooks.Events;
@@ -10,7 +11,7 @@
1011

1112
namespace Devlooped.Sponsors;
1213

13-
public class Webhook(SponsorsManager manager, IConfiguration config, IPushover notifier) : WebhookEventProcessor
14+
public class Webhook(SponsorsManager manager, IConfiguration config, IPushover notifier, ILogger<Webhook> logger) : WebhookEventProcessor
1415
{
1516
static ActivitySource tracer = ActivityTracer.Source;
1617

@@ -23,6 +24,34 @@ protected override async Task ProcessSponsorshipWebhookAsync(WebhookHeaders head
2324
}
2425

2526
protected override async Task ProcessIssueCommentWebhookAsync(WebhookHeaders headers, IssueCommentEvent payload, IssueCommentAction action)
27+
{
28+
try
29+
{
30+
await base.ProcessIssueCommentWebhookAsync(headers, payload, action);
31+
await IssueCommentWebhook(manager, notifier, payload, action);
32+
}
33+
catch (Exception e)
34+
{
35+
logger.LogError(e, e.Message);
36+
throw;
37+
}
38+
}
39+
40+
protected override async Task ProcessIssuesWebhookAsync(WebhookHeaders headers, IssuesEvent payload, IssuesAction action)
41+
{
42+
try
43+
{
44+
await base.ProcessIssuesWebhookAsync(headers, payload, action);
45+
await IssueWebhook(payload, action);
46+
}
47+
catch (Exception e)
48+
{
49+
logger.LogError(e, e.Message);
50+
throw;
51+
}
52+
}
53+
54+
static async Task IssueCommentWebhook(SponsorsManager manager, IPushover notifier, IssueCommentEvent payload, IssueCommentAction action)
2655
{
2756
using var activity = tracer.StartActivity("IssueComment");
2857
activity?.AddEvent(new ActivityEvent(action));
@@ -51,15 +80,11 @@ await notifier.PostAsync(new PushoverMessage
5180
});
5281
}
5382
}
54-
55-
await base.ProcessIssueCommentWebhookAsync(headers, payload, action);
5683
}
5784

58-
protected override async Task ProcessIssuesWebhookAsync(WebhookHeaders headers, IssuesEvent payload, IssuesAction action)
85+
async Task IssueWebhook(IssuesEvent payload, IssuesAction action)
5986
{
60-
await base.ProcessIssuesWebhookAsync(headers, payload, action);
61-
62-
using var activity = tracer.StartActivity();
87+
using var activity = tracer.StartActivity("Issue");
6388
activity?.AddEvent(new ActivityEvent(action));
6489

6590
activity?.SetTag("sender", payload.Sender?.Login);
@@ -97,12 +122,12 @@ protected override async Task ProcessIssuesWebhookAsync(WebhookHeaders headers,
97122
var definition = await client.Issue.Labels.Get(payload.Repository.Id, label);
98123
if (definition == null)
99124
{
100-
await client.Issue.Labels.Create(payload.Repository.Owner.Login, payload.Repository.Name, new NewLabel(label, color)
101-
{
125+
await client.Issue.Labels.Create(payload.Repository.Owner.Login, payload.Repository.Name, new NewLabel(label, color)
126+
{
102127
Description = sponsor.Kind == SponsorTypes.Contributor ?
103128
"Sponsor via contributions" :
104-
tier != null ?
105-
$"{CultureInfo.InvariantCulture.TextInfo.ToTitleCase(tier)} Sponsor" :
129+
tier != null ?
130+
$"{CultureInfo.InvariantCulture.TextInfo.ToTitleCase(tier)} Sponsor" :
106131
"Sponsor"
107132
});
108133
}

0 commit comments

Comments
 (0)