@@ -2,10 +2,12 @@ import * as crypto from 'crypto';
2
2
3
3
import { Injectable } from '@nestjs/common' ;
4
4
5
- import { configService } from '@kb-config' ;
5
+ import { configService , Logger } from '@kb-config' ;
6
6
7
7
@Injectable ( )
8
8
export class WebhooksService {
9
+ private readonly logger = new Logger ( WebhooksService . name ) ;
10
+
9
11
generateBitBucketWebhookApiToken ( body : any ) {
10
12
const bodyString = JSON . stringify ( body ) ;
11
13
@@ -31,24 +33,70 @@ export class WebhooksService {
31
33
}
32
34
33
35
handleBitBucketWebhook ( body : any ) {
34
- console . log ( 'BitBucket webhook received' ) ;
35
-
36
36
return {
37
37
message : 'Webhook received'
38
38
} ;
39
39
}
40
40
41
- handleGitHubWebhook ( body : any ) {
42
- console . log ( 'GitHub webhook received' ) ;
41
+ handleGitHubWebhook (
42
+ eventType : string ,
43
+ body : Record < string , any >
44
+ ) {
45
+ // event type: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads
46
+ if ( eventType === 'installation' && body . action === 'created' ) {
47
+ this . logger . debug ( 'GitHub App installation created' ) ;
48
+ return ;
49
+ }
43
50
44
- return {
45
- message : 'Webhook received'
46
- } ;
51
+ if ( eventType === 'installation' && body . action === 'deleted' ) {
52
+ this . logger . debug ( 'GitHub App installation deleted' ) ;
53
+ // return this.webhooksService.handleGitHubAppInstallationDeleted(body);
54
+ return ;
55
+ }
56
+
57
+ if ( eventType === 'installation_repositories' && body . action === 'added' ) {
58
+ this . logger . debug ( 'GitHub App installation repositories added' ) ;
59
+ // return this.webhooksService.handleGitHubAppInstallationRepositories(body);
60
+ return ;
61
+ }
62
+
63
+ if ( eventType === 'installation_repositories' && body . action === 'removed' ) {
64
+ this . logger . debug ( 'GitHub App installation repositories removed' ) ;
65
+ // return this.webhooksService.handleGitHubAppInstallationRepositoriesRemoved(body);
66
+ return ;
67
+ }
68
+
69
+ if ( eventType === 'push' ) {
70
+ this . logger . debug ( 'GitHub push event' ) ;
71
+ // return this.webhooksService.handleGitHubPush(body);
72
+ return ;
73
+ }
74
+
75
+ if ( eventType === 'pull_request' ) {
76
+ this . logger . debug ( 'GitHub pull request event' ) ;
77
+ // return this.webhooksService.handleGitHubPullRequest(body);
78
+ return ;
79
+ }
80
+
81
+ if ( eventType === 'pull_request_review' ) {
82
+ this . logger . debug ( 'GitHub pull request review event' ) ;
83
+ // return this.webhooksService.handleGitHubPullRequestReview(body);
84
+ return ;
85
+ }
86
+
87
+ if ( eventType === 'pull_request_review_comment' ) {
88
+ this . logger . debug ( 'GitHub pull request review comment event' ) ;
89
+ // return this.webhooksService.handleGitHubPullRequestReviewComment(body);
90
+ return ;
91
+ }
92
+
93
+ this . logger . debug ( 'GitHub event not handled' , {
94
+ eventType,
95
+ action : body . action
96
+ } ) ;
47
97
}
48
98
49
99
handleGitLabWebhook ( body : any ) {
50
- console . log ( 'GitLab webhook received' ) ;
51
-
52
100
return {
53
101
message : 'Webhook received'
54
102
} ;
0 commit comments