1
1
import { clusterEmbeddings } from '../../utils/cluster'
2
2
import { getEmbeddingsForIssue } from '../../utils/embeddings'
3
- import type { Issue } from '../../utils/github'
4
3
5
4
const linkedRepos : Record < string , string [ ] > = {
6
5
'danielroe/beasties' : [ 'GoogleChromeLabs/critters' ] ,
6
+ 'nitrojs/nitro' : [ 'unjs/h3' , 'unjs/c12' , 'unjs/unenv' , 'unjs/ofetch' ] ,
7
7
'nuxt/nuxt' : [ 'vuejs/core' , 'vitejs/vite' , 'nitrojs/nitro' ] ,
8
8
}
9
9
10
- const allowedRepos = [ 'nuxt/nuxt' , 'vuejs/vue ' , 'vitejs/vite' , 'nitrojs/nitro' , 'danielroe/beasties' ]
10
+ const allowedRepos = [ 'nuxt/nuxt' , 'vuejs/core ' , 'vitejs/vite' , 'nitrojs/nitro' , 'danielroe/beasties' , 'unjs/h3' , 'unjs/c12' , 'unjs/unenv' , 'unjs/ofetch ']
11
11
12
12
export default defineCachedEventHandler ( async ( event ) => {
13
13
const [ owner , repo ] = getRouterParam ( event , 'repo' ) ?. split ( '/' ) || [ ]
@@ -28,27 +28,30 @@ export default defineCachedEventHandler(async (event) => {
28
28
}
29
29
30
30
const repos = [ source , ...linkedRepos [ source ] || [ ] ]
31
- const issues = await Promise . all ( repos . map ( async repo => event . $fetch < Issue [ ] > ( `/api/issues/${ repo } ` ) ) )
31
+ const issues = await Promise . all ( repos . map ( async repo => $fetch ( `/api/issues/${ repo } ` ) ) )
32
32
. then ( r => r . flat ( ) )
33
33
34
34
console . log ( 'fetched' , issues . length , 'issues' )
35
35
36
+ const backlog = [ ...issues ]
36
37
const embeddings : number [ ] [ ] = [ ]
37
38
38
39
do {
39
- const batch = issues . splice ( 0 , 100 )
40
+ const batch = backlog . splice ( 0 , 100 )
40
41
embeddings . push ( ...await Promise . all ( batch . map ( async issue => getEmbeddingsForIssue ( event , issue ) ) ) )
41
- } while ( issues . length )
42
+ } while ( backlog . length )
42
43
44
+ console . log ( 'generated' , embeddings . length , 'embeddings' )
43
45
const clusters = clusterEmbeddings ( issues , embeddings )
46
+ console . log ( 'generated' , clusters . length , 'clusters' )
44
47
return clusters . filter ( ( cluster ) => {
45
48
return cluster . some ( issue => issue . repository ?. owner ?. name === owner && issue . repository ?. name === repo )
46
49
} )
47
50
} , {
48
51
swr : true ,
49
52
getKey ( event ) {
50
53
const [ owner , repo ] = getRouterParam ( event , 'repo' ) ?. split ( '/' ) || [ ]
51
- return `clusters:${ owner } :${ repo } `
54
+ return `clusters:${ owner } :${ repo } ` . toLowerCase ( )
52
55
} ,
53
56
maxAge : 60 * 60 * 1000 ,
54
57
staleMaxAge : 60 * 60 * 1000 ,
0 commit comments