Skip to content

Commit 7c56f01

Browse files
committed
chore: move back to parallel processing
1 parent bea8b76 commit 7c56f01

File tree

3 files changed

+167
-52
lines changed

3 files changed

+167
-52
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"nuxt": "latest",
2727
"nuxt-time": "1.0.3",
2828
"nuxt-webhook-validators": "0.1.4",
29+
"octokit": "^4.0.2",
2930
"ohash": "^1.1.4",
3031
"openai": "^4.76.0",
3132
"rgb-to-hsl": "^0.0.3",

pnpm-lock.yaml

+124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/routes/github/webhook.post.ts

+42-52
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Installation, InstallationLite, WebhookEvent } from '@octokit/webhooks-types'
22
import type { H3Event } from 'h3'
3-
import { createAppAuth } from '@octokit/auth-app'
4-
import { Octokit } from '@octokit/rest'
3+
import { App } from 'octokit'
54

65
import { indexIssue, removeIssue, storagePrefixForRepo } from '../../utils/embeddings'
76

@@ -14,58 +13,52 @@ export default defineEventHandler(async (event) => {
1413

1514
const body = await readBody<WebhookEvent>(event)
1615
const promises: Promise<unknown>[] = []
17-
try {
18-
if ('action' in body && 'installation' in body && !('client_payload' in body)) {
19-
if (body.action === 'created' && 'repositories' in body) {
20-
await addRepos(event, body.installation, body.repositories || [])
16+
if ('action' in body && 'installation' in body && !('client_payload' in body)) {
17+
if (body.action === 'created' && 'repositories' in body) {
18+
await addRepos(event, body.installation, body.repositories || [])
19+
}
20+
if (body.action === 'deleted' && 'repositories' in body) {
21+
for (const repo of body.repositories || []) {
22+
promises.push(deleteRepo(event, repo))
2123
}
22-
if (body.action === 'deleted' && 'repositories' in body) {
23-
for (const repo of body.repositories || []) {
24-
promises.push(deleteRepo(event, repo))
25-
}
24+
}
25+
if ((body.action === 'added' || body.action === 'removed')) {
26+
if ('repositories_added' in body) {
27+
promises.push(addRepos(event, body.installation, body.repositories_added))
2628
}
27-
if ((body.action === 'added' || body.action === 'removed')) {
28-
if ('repositories_added' in body) {
29-
await addRepos(event, body.installation, body.repositories_added)
30-
}
31-
if ('repositories_removed' in body) {
32-
for (const repo of body.repositories_removed) {
33-
promises.push(deleteRepo(event, repo))
34-
}
29+
if ('repositories_removed' in body) {
30+
for (const repo of body.repositories_removed) {
31+
promises.push(deleteRepo(event, repo))
3532
}
3633
}
37-
if (body.action === 'publicized' && body.installation) {
38-
await addRepos(event, body.installation, [body.repository])
39-
}
40-
if (body.action === 'privatized') {
41-
promises.push(deleteRepo(event, body.repository))
42-
}
4334
}
35+
if (body.action === 'publicized' && body.installation) {
36+
await addRepos(event, body.installation, [body.repository])
37+
}
38+
if (body.action === 'privatized') {
39+
promises.push(deleteRepo(event, body.repository))
40+
}
41+
}
4442

45-
if ('issue' in body) {
46-
switch (body.action) {
47-
case 'created':
48-
case 'edited':
49-
case 'opened':
50-
case 'reopened':
51-
promises.push(indexIssue(body.issue, body.repository))
52-
break
53-
54-
case 'closed':
55-
case 'deleted':
56-
promises.push(removeIssue(body.issue, body.repository))
57-
break
58-
}
43+
if ('issue' in body) {
44+
switch (body.action) {
45+
case 'created':
46+
case 'edited':
47+
case 'opened':
48+
case 'reopened':
49+
promises.push(indexIssue(body.issue, body.repository))
50+
break
51+
52+
case 'closed':
53+
case 'deleted':
54+
promises.push(removeIssue(body.issue, body.repository))
55+
break
5956
}
57+
}
6058

61-
event.waitUntil(Promise.allSettled(promises))
59+
event.waitUntil(Promise.allSettled(promises))
6260

63-
return null
64-
}
65-
catch (err) {
66-
console.error(err)
67-
throw err
68-
}
61+
return null
6962
})
7063

7164
export type InstallationRepo = {
@@ -78,14 +71,11 @@ export type InstallationRepo = {
7871

7972
async function addRepos(event: H3Event, installation: Installation | InstallationLite, repos: InstallationRepo[]) {
8073
const config = useRuntimeConfig(event)
81-
const octokit = new Octokit({
82-
authStrategy: createAppAuth,
83-
auth: {
84-
appId: config.github.appId,
85-
privateKey: config.github.privateKey,
86-
installationId: installation.id,
87-
},
74+
const app = new App({
75+
appId: config.github.appId,
76+
privateKey: config.github.privateKey,
8877
})
78+
const octokit = await app.getInstallationOctokit(installation.id)
8979

9080
for (const repo of repos) {
9181
if (repo.private) {

0 commit comments

Comments
 (0)