@@ -15,6 +15,12 @@ export default defineEventHandler(async (event) => {
15
15
const body = await readBody < WebhookEvent > ( event )
16
16
const promises : Promise < unknown > [ ] = [ ]
17
17
if ( 'action' in body && 'installation' in body && ! ( 'client_payload' in body ) ) {
18
+ if ( 'repository' in body && body . installation && body . repository ) {
19
+ const repoMetadata = await hubKV ( ) . getItem < RepoMetadata > ( `repo:${ body . repository . owner . login } :${ body . repository . name } ` )
20
+ if ( repoMetadata && ! repoMetadata . indexed ) {
21
+ promises . push ( addRepos ( event , body . installation , [ body . repository ] ) )
22
+ }
23
+ }
18
24
if ( body . action === 'created' && 'repositories' in body ) {
19
25
promises . push ( addRepos ( event , body . installation , body . repositories || [ ] ) )
20
26
}
@@ -70,6 +76,10 @@ export type InstallationRepo = {
70
76
private : boolean
71
77
}
72
78
79
+ type RepoMetadata = InstallationRepo & {
80
+ indexed : boolean
81
+ }
82
+
73
83
async function addRepos ( event : H3Event , installation : Installation | InstallationLite , repos : InstallationRepo [ ] ) {
74
84
const config = useRuntimeConfig ( event )
75
85
const octokit = new Octokit ( {
@@ -92,7 +102,7 @@ async function addRepos(event: H3Event, installation: Installation | Installatio
92
102
const [ owner , name ] = repo . full_name . split ( '/' )
93
103
94
104
const promises : Array < Promise < unknown > > = [ ]
95
- promises . push ( kv . setItem ( `repo:${ owner } :${ name } ` , { ...repo , indexed : false } ) )
105
+ promises . push ( kv . setItem ( `repo:${ owner } :${ name } ` , { ...repo , indexed : false } satisfies RepoMetadata ) )
96
106
97
107
await octokit . paginate ( octokit . rest . issues . listForRepo , {
98
108
owner : owner ! ,
@@ -115,7 +125,7 @@ async function addRepos(event: H3Event, installation: Installation | Installatio
115
125
116
126
console . log ( 'added' , promises . length - 1 , 'issues from' , `${ owner } /${ name } ` , 'to the index' )
117
127
118
- event . waitUntil ( kv . setItem ( `repo:${ owner } :${ name } ` , { ...repo , indexed : true } ) )
128
+ event . waitUntil ( kv . setItem ( `repo:${ owner } :${ name } ` , { ...repo , indexed : true } satisfies RepoMetadata ) )
119
129
}
120
130
}
121
131
0 commit comments