@@ -13,53 +13,58 @@ export default defineEventHandler(async (event) => {
13
13
14
14
const body = await readBody < WebhookEvent > ( event )
15
15
const promises : Promise < unknown > [ ] = [ ]
16
-
17
- if ( 'action' in body && 'installation' in body && ! ( 'client_payload' in body ) ) {
18
- if ( body . action === 'created' && 'repositories' in body ) {
19
- promises . push ( addRepos ( event , body . installation , body . repositories || [ ] ) )
20
- }
21
- if ( body . action === 'deleted' && 'repositories' in body ) {
22
- for ( const repo of body . repositories || [ ] ) {
23
- promises . push ( deleteRepo ( event , repo ) )
24
- }
25
- }
26
- if ( ( body . action === 'added' || body . action === 'removed' ) ) {
27
- if ( 'repositories_added' in body ) {
28
- promises . push ( addRepos ( event , body . installation , body . repositories_added ) )
16
+ try {
17
+ if ( 'action' in body && 'installation' in body && ! ( 'client_payload' in body ) ) {
18
+ if ( body . action === 'created' && 'repositories' in body ) {
19
+ await addRepos ( event , body . installation , body . repositories || [ ] )
29
20
}
30
- if ( 'repositories_removed ' in body ) {
31
- for ( const repo of body . repositories_removed ) {
21
+ if ( body . action === 'deleted' && 'repositories ' in body ) {
22
+ for ( const repo of body . repositories || [ ] ) {
32
23
promises . push ( deleteRepo ( event , repo ) )
33
24
}
34
25
}
26
+ if ( ( body . action === 'added' || body . action === 'removed' ) ) {
27
+ if ( 'repositories_added' in body ) {
28
+ await addRepos ( event , body . installation , body . repositories_added )
29
+ }
30
+ if ( 'repositories_removed' in body ) {
31
+ for ( const repo of body . repositories_removed ) {
32
+ promises . push ( deleteRepo ( event , repo ) )
33
+ }
34
+ }
35
+ }
36
+ if ( body . action === 'publicized' && body . installation ) {
37
+ await addRepos ( event , body . installation , [ body . repository ] )
38
+ }
39
+ if ( body . action === 'privatized' ) {
40
+ promises . push ( deleteRepo ( event , body . repository ) )
41
+ }
35
42
}
36
- if ( body . action === 'publicized' && body . installation ) {
37
- promises . push ( addRepos ( event , body . installation , [ body . repository ] ) )
38
- }
39
- if ( body . action === 'privatized' ) {
40
- promises . push ( deleteRepo ( event , body . repository ) )
41
- }
42
- }
43
43
44
- if ( 'issue' in body ) {
45
- switch ( body . action ) {
46
- case 'created' :
47
- case 'edited' :
48
- case 'opened' :
49
- case 'reopened' :
50
- promises . push ( indexIssue ( body . issue , body . repository ) )
51
- break
52
-
53
- case 'closed' :
54
- case 'deleted' :
55
- promises . push ( removeIssue ( body . issue , body . repository ) )
56
- break
44
+ if ( 'issue' in body ) {
45
+ switch ( body . action ) {
46
+ case 'created' :
47
+ case 'edited' :
48
+ case 'opened' :
49
+ case 'reopened' :
50
+ promises . push ( indexIssue ( body . issue , body . repository ) )
51
+ break
52
+
53
+ case 'closed' :
54
+ case 'deleted' :
55
+ promises . push ( removeIssue ( body . issue , body . repository ) )
56
+ break
57
+ }
57
58
}
58
- }
59
59
60
- event . waitUntil ( Promise . allSettled ( promises ) )
60
+ event . waitUntil ( Promise . allSettled ( promises ) )
61
61
62
- return null
62
+ return null
63
+ }
64
+ catch ( err ) {
65
+ console . error ( err )
66
+ throw err
67
+ }
63
68
} )
64
69
65
70
export type InstallationRepo = {
0 commit comments