Skip to content

Commit 28227de

Browse files
committed
chore: log issues with adding repos
1 parent c780b44 commit 28227de

File tree

1 file changed

+43
-38
lines changed

1 file changed

+43
-38
lines changed

server/routes/github/webhook.post.ts

+43-38
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,58 @@ export default defineEventHandler(async (event) => {
1313

1414
const body = await readBody<WebhookEvent>(event)
1515
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 || [])
2920
}
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 || []) {
3223
promises.push(deleteRepo(event, repo))
3324
}
3425
}
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+
}
3542
}
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-
}
4343

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+
}
5758
}
58-
}
5959

60-
event.waitUntil(Promise.allSettled(promises))
60+
event.waitUntil(Promise.allSettled(promises))
6161

62-
return null
62+
return null
63+
}
64+
catch (err) {
65+
console.error(err)
66+
throw err
67+
}
6368
})
6469

6570
export type InstallationRepo = {

0 commit comments

Comments
 (0)