-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·41 lines (34 loc) · 1.08 KB
/
index.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
#!/usr/bin/env node
const username = process.argv[2] || 'benjycui';
const GitHub = require('github');
const github = new GitHub();
async function getAllCommits(user) {
let commits = [];
let res = await github.search.commits({
q: `author:${user} merge:false`,
sort: 'author-date',
'per_page': 100,
});
commits = commits.concat(res.data.items);
while(github.hasNextPage(res)) {
res = await github.getNextPage(res);
commits = commits.concat(res.data.items);
}
return commits;
}
async function getAllReposContributed(user) {
const commits = await getAllCommits(user);
const repos = commits.map(({ repository }) => repository)
.filter(repo => !repo.fork)
.map(({ full_name }) => full_name)
const unique = {};
repos.forEach(r => unique[r] = true);
return Object.keys(unique);
}
console.log('In progress...');
getAllReposContributed(username)
.then(repos => {
console.log(`${username} had contributed to ${repos.length} repositories.`);
repos.forEach((r, i) => console.log(`${i + 1}. ${r}`));
})
.catch(e => console.error(e))