-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunfollow.js
33 lines (25 loc) · 1.18 KB
/
unfollow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(async () => {
const { Octokit } = await import("@octokit/rest");
// create a personal access token at https://github.com/settings/tokens/new?scopes=user:follow&description=Unfollow+Script+Token
const octokit = new Octokit({ auth: `your_token_with_correct_permission` });
async function unfollowNonFollowers() {
const username = 'your_username';
// Get list of users who are following you
const followers = await octokit.paginate(octokit.rest.users.listFollowersForUser, { username });
const followerLogins = followers.map(user => user.login);
// Get list of users you are following
const following = await octokit.paginate(octokit.rest.users.listFollowingForUser, { username });
const followingLogins = following.map(user => user.login);
let unfollowedCount = 0;
// Unfollow users who are not following you
for (const user of followingLogins) {
if (!followerLogins.includes(user)) {
await octokit.rest.users.unfollow({ username: user });
unfollowedCount++;
}
}
// Log the total number of unfollowed users
console.log(`unfollowed ${unfollowedCount} users`);
}
unfollowNonFollowers().catch(console.error);
})();