1
1
using System . Diagnostics ;
2
2
using System . Globalization ;
3
3
using Microsoft . Extensions . Configuration ;
4
+ using Microsoft . Extensions . Logging ;
4
5
using Octokit ;
5
6
using Octokit . Webhooks ;
6
7
using Octokit . Webhooks . Events ;
10
11
11
12
namespace Devlooped . Sponsors ;
12
13
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
14
15
{
15
16
static ActivitySource tracer = ActivityTracer . Source ;
16
17
@@ -23,6 +24,34 @@ protected override async Task ProcessSponsorshipWebhookAsync(WebhookHeaders head
23
24
}
24
25
25
26
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 )
26
55
{
27
56
using var activity = tracer . StartActivity ( "IssueComment" ) ;
28
57
activity ? . AddEvent ( new ActivityEvent ( action ) ) ;
@@ -51,15 +80,11 @@ await notifier.PostAsync(new PushoverMessage
51
80
} ) ;
52
81
}
53
82
}
54
-
55
- await base . ProcessIssueCommentWebhookAsync ( headers , payload , action ) ;
56
83
}
57
84
58
- protected override async Task ProcessIssuesWebhookAsync ( WebhookHeaders headers , IssuesEvent payload , IssuesAction action )
85
+ async Task IssueWebhook ( IssuesEvent payload , IssuesAction action )
59
86
{
60
- await base . ProcessIssuesWebhookAsync ( headers , payload , action ) ;
61
-
62
- using var activity = tracer . StartActivity ( ) ;
87
+ using var activity = tracer . StartActivity ( "Issue" ) ;
63
88
activity ? . AddEvent ( new ActivityEvent ( action ) ) ;
64
89
65
90
activity ? . SetTag ( "sender" , payload . Sender ? . Login ) ;
@@ -97,12 +122,12 @@ protected override async Task ProcessIssuesWebhookAsync(WebhookHeaders headers,
97
122
var definition = await client . Issue . Labels . Get ( payload . Repository . Id , label ) ;
98
123
if ( definition == null )
99
124
{
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
+ {
102
127
Description = sponsor . Kind == SponsorTypes . Contributor ?
103
128
"Sponsor via contributions" :
104
- tier != null ?
105
- $ "{ CultureInfo . InvariantCulture . TextInfo . ToTitleCase ( tier ) } Sponsor" :
129
+ tier != null ?
130
+ $ "{ CultureInfo . InvariantCulture . TextInfo . ToTitleCase ( tier ) } Sponsor" :
106
131
"Sponsor"
107
132
} ) ;
108
133
}
0 commit comments