-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
80 lines (66 loc) · 1.8 KB
/
server.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
73
74
75
76
77
78
79
80
var express = require('express');
var bodyParser = require('body-parser');
var https = require('https');
var app = express();
app.use(bodyParser.json());
app.listen(3000, function () {
console.log('Server listening on', 3000)
});
var GitHubApi = require("github");
var github = new GitHubApi({
version: "3.0.0",
debug: true,
protocol: "https",
host: "api.github.com",
pathPrefix: "",
timeout: 10000
});
// usage: http://localhost:3000/contributors?user=shulamyt&repo=break-the-code
app.get('/contributors', function (req, res) {
var user = req.param("user");
var repo = req.param("repo");
var page = 1; //TODO: foreach page..
getContributors(user, repo, page);
});
var canBeMore = function(res, per_page){
return false;
};
var getUserDetails = function(username){
//github.authenticate({
// type: "basic",
// username: username//,
// //password: "mysecretpass"
//});
//
//github.user.get({
// //user: username
//}, function(err, res){
// console.log(JSON.stringify(err));
// console.log(JSON.stringify(res));
//});
};
var handleContributors = function(contributors){
for(i in contributors){
var contributor = contributors[i];
var username = contributor.login;
getUserDetails(username);
console.log(JSON.stringify(contributor));
}
};
var getContributors = function(user, repo, page){
var per_page = 100;
github.repos.getContributors({
user: user,
repo: repo,
per_page: per_page
}, function(err, res){
if(err){
console.log(JSON.stringify(err));
}
handleContributors(res);
if(canBeMore(res, per_page)){
var page = page + 1;
getContributors(user, repo, page);
}
});
};