forked from subodh-dharma/star-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
53 lines (46 loc) · 1.41 KB
/
main.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
//var github = require('./github.js');
var git = require('octonode').client();
var star_summary = [];
var username = '';
if (process.argv.slice(2)[0]) {
username = process.argv.slice(2)[0];
} else {
console.log('Missing Arguments! \n Usage: node main.js <github-user-name>');
process.exit(1);
}
var ghuser = git.user(username);
getRepoStarCount(ghuser).then(function(star_summary) {
// sorting the array in decreasing order of star gazers.
star_summary.sort(function(a, b) {
return b.star_count - a.star_count;
});
console.log(JSON.stringify(star_summary, null, 4));
var sindex = 0;
for (star in star_summary) {
if ((parseInt(star) + 1) <= star_summary[star].star_count) {
sindex++;
} else {
break;
}
}
console.log('Star Index :', sindex);
});
function getRepoStarCount(ghuser) {
return new Promise(function(resolve, reject) {
ghuser.repos(function(error, repos, headers) {
for (repo in repos) {
//console.log(JSON.stringify(repos[repo], null, 4));
var r = repos[repo];
if (r.stargazers_count != 0) {
star_summary.push({
'name': r.name,
'star_count': r.stargazers_count
});
}
//console.log(JSON.stringify(star_summary, null, 4));
//console.log("Repository: " + r.name, "\tStarred by " + r.stargazers_count + " developer(s)");
}
resolve(star_summary);
});
});
}