Skip to content

Commit 47d08dd

Browse files
authored
fix: get all followers list
1 parent c923c8d commit 47d08dd

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

scripts/src/fetchFollowers.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,38 @@ const octokit = new Octokit({
1616

1717
const 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
}

0 commit comments

Comments
 (0)