forked from ghuser-io/db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindUsersToRemove.js
executable file
·72 lines (55 loc) · 2.06 KB
/
findUsersToRemove.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env node
'use strict';
(async () => {
const fs = require('fs');
const ora = require('ora');
const path = require('path');
const data = require('./impl/data');
const DbFile = require('./impl/dbFile');
const github = require('./impl/github');
const scriptUtils = require('./impl/scriptUtils');
scriptUtils.printUnhandledRejections();
await findUsersToRemove();
return;
async function findUsersToRemove() {
// The goal is to find users who meet all these criteria:
// * have had their profiles for a while,
// * aren't marked not to be deleted, and
// * haven't starred the project.
let spinner;
const now = new Date;
const minAgeMonths = 1;
const users = [];
for (const file of fs.readdirSync(data.users)) {
if (file.endsWith('.json')) {
const user = new DbFile(path.join(data.users, file));
if (!user.ghuser_deleted_because && !user.ghuser_keep_because && !user.removed_from_github
&& now - Date.parse(user.ghuser_created_at) > minAgeMonths * 30 * 24 * 60 * 60 * 1000) {
users.push(user);
}
}
}
const stargazers = await fetchStargazers('ghuser-io/ghuser.io');
const toRemove = users.map(user => user.login).filter(user => stargazers.indexOf(user) === -1);
if (toRemove.length) {
console.log(`
Create this issue on GitHub:
[question] Do you like your profile?
Hi :)
to make sure we're not wasting resources, I'd like to know if you'd like to keep your profile up and running:
`);
for (const user of toRemove) {
console.log(`* @${user}: https://ghuser.io/${user}`);
}
console.log("\nJust give me a quick sign and I won't bother you again. Thanks!");
}
return;
async function fetchStargazers(repo) {
const ghUrl = `https://api.github.com/repos/${repo}/stargazers`;
spinner = ora(`Fetching ${ghUrl}...`).start();
const ghDataJson = await github.fetchGHJson(ghUrl, spinner);
spinner.succeed(`Fetched ${ghUrl}`);
return ghDataJson.map(stargazer => stargazer.login);
}
}
})();