File tree Expand file tree Collapse file tree 1 file changed +22
-8
lines changed Expand file tree Collapse file tree 1 file changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -16,24 +16,38 @@ const octokit = new Octokit({
1616
1717const getLatestFollowers = async ( ) => {
1818 const username = "pulkitxm" ;
19+ let followers = [ ] ;
20+ let page = 1 ;
21+ const perPage = 100 ;
22+ let hasMore = true ;
23+
1924 try {
20- const { data } = await octokit . rest . users . listFollowersForAuthenticatedUser (
21- {
25+ while ( hasMore ) {
26+ const { data } = await octokit . rest . users . listFollowersForAuthenticatedUser ( {
2227 username : username ,
23- per_page : 1000000000000 ,
24- } ,
25- ) ;
28+ per_page : perPage ,
29+ page : page ,
30+ } ) ;
31+
32+ followers = followers . concat ( data ) ;
33+
34+ if ( data . length < perPage ) {
35+ hasMore = false ;
36+ } else {
37+ page ++ ;
38+ }
39+ }
2640
27- const followers = data . map ( ( follower ) => ( {
41+ const formattedFollowers = followers . map ( ( follower ) => ( {
2842 profileUrl : follower . html_url ,
2943 picUrl : follower . avatar_url ,
3044 } ) ) ;
3145
32- followers . sort ( ( a , b ) => {
46+ formattedFollowers . sort ( ( a , b ) => {
3347 return a . profileUrl . localeCompare ( b . profileUrl ) ;
3448 } ) ;
3549
36- return followers ;
50+ return formattedFollowers ;
3751 } catch ( error ) {
3852 console . error ( "Error fetching followers:" , error . message ) ;
3953 }
You can’t perform that action at this time.
0 commit comments