1
1
import type { Installation , InstallationLite , WebhookEvent } from '@octokit/webhooks-types'
2
2
import type { H3Event } from 'h3'
3
- import { App } from 'octokit'
3
+ import { createAppAuth } from '@octokit/auth-app'
4
+ import { Octokit } from '@octokit/rest'
4
5
5
6
import { indexIssue , removeIssue , storagePrefixForRepo } from '../../utils/embeddings'
6
7
@@ -15,7 +16,7 @@ export default defineEventHandler(async (event) => {
15
16
const promises : Promise < unknown > [ ] = [ ]
16
17
if ( 'action' in body && 'installation' in body && ! ( 'client_payload' in body ) ) {
17
18
if ( body . action === 'created' && 'repositories' in body ) {
18
- await addRepos ( event , body . installation , body . repositories || [ ] )
19
+ promises . push ( addRepos ( event , body . installation , body . repositories || [ ] ) )
19
20
}
20
21
if ( body . action === 'deleted' && 'repositories' in body ) {
21
22
for ( const repo of body . repositories || [ ] ) {
@@ -33,7 +34,7 @@ export default defineEventHandler(async (event) => {
33
34
}
34
35
}
35
36
if ( body . action === 'publicized' && body . installation ) {
36
- await addRepos ( event , body . installation , [ body . repository ] )
37
+ promises . push ( addRepos ( event , body . installation , [ body . repository ] ) )
37
38
}
38
39
if ( body . action === 'privatized' ) {
39
40
promises . push ( deleteRepo ( event , body . repository ) )
@@ -71,11 +72,14 @@ export type InstallationRepo = {
71
72
72
73
async function addRepos ( event : H3Event , installation : Installation | InstallationLite , repos : InstallationRepo [ ] ) {
73
74
const config = useRuntimeConfig ( event )
74
- const app = new App ( {
75
- appId : config . github . appId ,
76
- privateKey : config . github . privateKey ,
75
+ const octokit = new Octokit ( {
76
+ authStrategy : createAppAuth ,
77
+ auth : {
78
+ appId : config . github . appId ,
79
+ privateKey : config . github . privateKey ,
80
+ installationId : installation . id ,
81
+ } ,
77
82
} )
78
- const octokit = await app . getInstallationOctokit ( installation . id )
79
83
80
84
for ( const repo of repos ) {
81
85
if ( repo . private ) {
0 commit comments