@@ -15,14 +15,33 @@ interface Contributor {
15
15
const url = new URL (' /repos/webpro-nl/knip/contributors' , ' https://api.github.com' );
16
16
url .searchParams .set (' per_page' , ' 100' );
17
17
18
- const contributors: Contributor [] = isFetch
19
- ? await fetch (url .href , {
18
+ const getAllContributors = async (url : URL ) => {
19
+ const allContributors: Contributor [] = [];
20
+ let nextUrl: string = url .href ;
21
+
22
+ console .log (' \n ' );
23
+ while (nextUrl ) {
24
+ console .log (` Fetching contributors from ${nextUrl } ` );
25
+ const response = await fetch (nextUrl , {
20
26
headers: {
21
27
Accept: ' application/vnd.github+json' ,
22
28
Authorization: ` Bearer ${GITHUB_TOKEN } ` ,
23
29
' X-GitHub-Api-Version' : ' 2022-11-28' ,
24
30
},
25
- }).then (res => res .json ())
31
+ });
32
+
33
+ const contributors = await response .json ();
34
+ allContributors .push (... contributors );
35
+
36
+ const linkHeader = response .headers .get (' Link' );
37
+ nextUrl = linkHeader ?.match (/ <([^ >] + )>;\s * rel="next"/ )?.[1 ] || ' ' ;
38
+ }
39
+
40
+ return allContributors ;
41
+ };
42
+
43
+ const contributors: Contributor [] = isFetch
44
+ ? await getAllContributors (url )
26
45
: JSON .parse (await readFile (' mock/contributors.json' , ' utf-8' ));
27
46
28
47
if (! Array .isArray (contributors )) console .log (contributors );
0 commit comments