This repository was archived by the owner on Aug 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
88 lines (75 loc) · 2.73 KB
/
Copy pathindex.js
File metadata and controls
88 lines (75 loc) · 2.73 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const https = require('https');
const username = process.argv[2];
if (!username) {
console.log('Usage: node index.js <github-username>');
process.exit(1);
}
const fetch = (url) => {
return new Promise((resolve, reject) => {
const urlObj = new URL(url);
https.get({
hostname: urlObj.hostname,
path: urlObj.pathname + urlObj.search,
headers: { 'User-Agent': 'Node.js' }
}, (res) => {
if (res.statusCode === 301 || res.statusCode === 302) {
return fetch(res.headers.location).then(resolve).catch(reject);
}
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => resolve({ ok: res.statusCode === 200, data }));
}).on('error', reject);
});
};
const cleanEmail = (email) => email.replace(/['"]/g, '').trim().toLowerCase();
const extractEmails = (patch) => {
const matches = patch.match(/^From: .+ <(.+)>/gm) || [];
return matches.map(m => cleanEmail(m.match(/<(.+)>/)?.[1] || '')).filter(Boolean);
};
const delay = (ms) => new Promise(r => setTimeout(r, ms));
const main = async () => {
const emails = new Set();
const seen = new Set();
// Scan events
for (let p = 1; p <= 10; p++) {
const res = await fetch(`https://api.github.com/users/${username}/events/public?per_page=100&page=${p}`);
if (!res.ok) break;
const events = JSON.parse(res.data);
if (!events.length) break;
for (const e of events) {
if (e.type !== 'PushEvent') continue;
for (const c of e.payload?.commits || []) {
if (seen.has(c.sha)) continue;
seen.add(c.sha);
try {
const patch = await fetch(`https://github.com/${e.repo?.name}/commit/${c.sha}.patch`);
if (patch.ok) extractEmails(patch.data).forEach(x => emails.add(x));
} catch {}
await delay(50);
}
}
}
// Scan repos
const repos = await fetch(`https://api.github.com/users/${username}/repos?per_page=100`);
if (repos.ok) {
for (const repo of JSON.parse(repos.data).filter(r => !r.fork)) {
for (let p = 1; p <= 5; p++) {
const res = await fetch(`https://api.github.com/repos/${username}/${repo.name}/commits?per_page=100&page=${p}`);
if (!res.ok) break;
const commits = JSON.parse(res.data);
if (!commits.length) break;
for (const c of commits) {
if (seen.has(c.sha)) continue;
seen.add(c.sha);
try {
const patch = await fetch(`https://github.com/${username}/${repo.name}/commit/${c.sha}.patch`);
if (patch.ok) extractEmails(patch.data).forEach(x => emails.add(x));
} catch {}
await delay(50);
}
}
}
}
console.log([...emails].sort().join('\n') || 'No emails found');
};
main().catch(console.error);