-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.js
84 lines (68 loc) · 1.82 KB
/
parser.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
81
82
83
84
(function () {
function getHomeWorks(host) {
var dfd = $.Deferred();
$.get(host).done(function (html) {
var homeworks = $(html).find('.js-repo-list').find('h3 a')
.map(function () {
return $(this).text();
})
.get()
.filter(function (item) {
return (/^dz-/).test(item);
})
.sort();
dfd.resolve(homeworks);
});
return dfd.promise();
}
function getPullRequests(repo) {
var dfd = $.Deferred();
$.get('/cripi-javascript/' + repo + '/pulls')
.done(function (html) {
var pulls = $(html).find('.pulls-list').find('.gravatar')
.map(function () {
return $(this).attr('href').replace('/', '');
})
.get();
dfd.resolve({
repo: repo,
pulls: pulls
});
});
return dfd.promise();
}
function printResultsTable(results) {
var headers = ['name'],
table = [],
index = {};
results.forEach(function (task) {
headers.push(task.repo);
task.pulls.forEach(function (student) {
if (!index[student]) {
index[student] = {};
index[student].name = student;
index[student].total = 0;
table.push(index[student]);
}
index[student][task.repo] = 1;
index[student].total++;
});
});
headers.push('total');
if (console.table) {
console.table(table, headers);
} else {
console.log(table);
}
}
getHomeWorks('/cripi-javascript')
.then(function (homeworks) {
var promises = homeworks.map(function (homework) {
return getPullRequests(homework);
});
return $.when.apply($, promises);
})
.then(function () {
printResultsTable([].slice.call(arguments));
});
}());