Skip to content

Commit ab3fcd7

Browse files
committed
fix: only index public repos
1 parent 6c78807 commit ab3fcd7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

server/routes/github/webhook.post.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Installation, WebhookEvent } from '@octokit/webhooks-types'
1+
import type { Installation, InstallationLite, WebhookEvent } from '@octokit/webhooks-types'
22
import type { H3Event } from 'h3'
33
import { App } from 'octokit'
44

@@ -15,7 +15,6 @@ export default defineEventHandler(async (event) => {
1515
const promises: Promise<unknown>[] = []
1616

1717
if ('action' in body && 'installation' in body && !('client_payload' in body)) {
18-
// new installation
1918
if (body.action === 'created' && 'repositories' in body) {
2019
for (const repo of body.repositories || []) {
2120
promises.push(addRepo(event, body.installation, repo))
@@ -38,6 +37,12 @@ export default defineEventHandler(async (event) => {
3837
}
3938
}
4039
}
40+
if (body.action === 'publicized' && body.installation) {
41+
promises.push(addRepo(event, body.installation, body.repository))
42+
}
43+
if (body.action === 'privatized') {
44+
promises.push(deleteRepo(event, body.repository))
45+
}
4146
}
4247

4348
if ('issue' in body) {
@@ -69,7 +74,10 @@ export type InstallationRepo = {
6974
private: boolean
7075
}
7176

72-
async function addRepo(event: H3Event, installation: Installation, repo: InstallationRepo) {
77+
async function addRepo(event: H3Event, installation: Installation | InstallationLite, repo: InstallationRepo) {
78+
if (repo.private) {
79+
return
80+
}
7381
const config = useRuntimeConfig(event)
7482
const app = new App({
7583
appId: config.github.appId,

0 commit comments

Comments
 (0)