11import { z } from "zod" ;
22import { useOctokitApp } from "../../utils/octokit" ;
33import stringSimilarity from "string-similarity" ;
4+ import type { RepoNode } from "../../utils/types" ;
45
56const querySchema = z . object ( {
67 text : z . string ( ) ,
@@ -20,32 +21,47 @@ export default defineEventHandler(async (event) => {
2021 const searchText = query . text . toLowerCase ( ) ;
2122 const matches : RepoNode [ ] = [ ] ;
2223
23- await app . eachRepository ( async ( { repository } ) => {
24+ await app . eachInstallation ( async ( { octokit , installation } ) => {
2425 if ( signal . aborted ) return ;
25- if ( repository . private ) return ;
26+
27+ if ( installation . suspended_at ) {
28+ console . warn ( `Skipping suspended installation ${ installation . id } ` ) ;
29+ return ;
30+ }
2631
27- const repoName = repository . name . toLowerCase ( ) ;
28- const ownerLogin = repository . owner . login . toLowerCase ( ) ;
32+ try {
33+ const repos = await octokit . paginate ( "GET /installation/repositories" ) ;
2934
30- const nameScore = stringSimilarity . compareTwoStrings (
31- repoName ,
32- searchText ,
33- ) ;
34- const ownerScore = stringSimilarity . compareTwoStrings (
35- ownerLogin ,
36- searchText ,
37- ) ;
35+ for ( const repository of repos ) {
36+ if ( signal . aborted ) return ;
37+ if ( repository . private ) continue ;
3838
39- matches . push ( {
40- id : repository . id ,
41- name : repository . name ,
42- owner : {
43- login : repository . owner . login ,
44- avatarUrl : repository . owner . avatar_url ,
45- } ,
46- stars : repository . stargazers_count || 0 ,
47- score : Math . max ( nameScore , ownerScore ) ,
48- } ) ;
39+ const repoName = repository . name . toLowerCase ( ) ;
40+ const ownerLogin = repository . owner . login . toLowerCase ( ) ;
41+
42+ const nameScore = stringSimilarity . compareTwoStrings (
43+ repoName ,
44+ searchText ,
45+ ) ;
46+ const ownerScore = stringSimilarity . compareTwoStrings (
47+ ownerLogin ,
48+ searchText ,
49+ ) ;
50+
51+ matches . push ( {
52+ id : repository . id ,
53+ name : repository . name ,
54+ owner : {
55+ login : repository . owner . login ,
56+ avatarUrl : repository . owner . avatar_url ,
57+ } ,
58+ stars : repository . stargazers_count || 0 ,
59+ score : Math . max ( nameScore , ownerScore ) ,
60+ } ) ;
61+ }
62+ } catch ( error ) {
63+ console . warn ( `Error fetching repositories for installation ${ installation . id } :` , error ) ;
64+ }
4965 } ) ;
5066
5167 matches . sort ( ( a , b ) =>
0 commit comments