1- import type { H3Event } from 'h3'
2-
31export interface GitHubContributor {
42 login : string
53 id : number
@@ -9,28 +7,47 @@ export interface GitHubContributor {
97}
108
119export default defineCachedEventHandler (
12- async ( _event : H3Event ) : Promise < GitHubContributor [ ] > => {
13- const response = await fetch (
14- 'https://api.github.com/repos/npmx-dev/npmx.dev/contributors?per_page=50' ,
15- {
16- headers : {
17- 'Accept' : 'application/vnd.github.v3+json' ,
18- 'User-Agent' : 'npmx' ,
10+ async ( ) : Promise < GitHubContributor [ ] > => {
11+ const allContributors : GitHubContributor [ ] = [ ]
12+ let page = 1
13+ const perPage = 100
14+
15+ while ( true ) {
16+ const response = await fetch (
17+ `https://api.github.com/repos/npmx-dev/npmx.dev/contributors?per_page=${ perPage } &page=${ page } ` ,
18+ {
19+ headers : {
20+ 'Accept' : 'application/vnd.github.v3+json' ,
21+ 'User-Agent' : 'npmx' ,
22+ } ,
1923 } ,
20- } ,
21- )
22-
23- if ( ! response . ok ) {
24- throw createError ( {
25- statusCode : response . status ,
26- message : 'Failed to fetch contributors' ,
27- } )
28- }
24+ )
25+
26+ if ( ! response . ok ) {
27+ throw createError ( {
28+ statusCode : response . status ,
29+ message : 'Failed to fetch contributors' ,
30+ } )
31+ }
32+
33+ const contributors = ( await response . json ( ) ) as GitHubContributor [ ]
2934
30- const contributors = ( await response . json ( ) ) as GitHubContributor [ ]
35+ if ( contributors . length === 0 ) {
36+ break
37+ }
38+
39+ allContributors . push ( ...contributors )
40+
41+ // If we got fewer than perPage results, we've reached the end
42+ if ( contributors . length < perPage ) {
43+ break
44+ }
45+
46+ page ++
47+ }
3148
3249 // Filter out bots
33- return contributors . filter ( c => ! c . login . includes ( '[bot]' ) )
50+ return allContributors . filter ( c => ! c . login . includes ( '[bot]' ) )
3451 } ,
3552 {
3653 maxAge : 3600 , // Cache for 1 hour
0 commit comments