-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updatefile.js
62 lines (50 loc) · 1.41 KB
/
updatefile.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
'use strict';
var each = require('async-each');
var contributors = require('github-contributors');
var stringify = require('stringify-author');
var GitHub = require('github-base');
module.exports = function(app) {
var github;
var auth;
app.task('authenticate', function(cb) {
auth = {
username: app.options.username || app.options.u,
password: app.options.password || app.options.p
};
github = new GitHub(auth);
cb();
});
app.task('default', ['authenticate'], function(cb) {
var data = app.pkg.expand();
contributors(data.repo, auth, function(err, arr) {
if (err) return cb(err);
if (!Array.isArray(arr) || arr.length <= 1) {
cb();
return;
}
users(arr, function(err, contributors) {
if (err) return cb(err);
app.pkg.set('contributors', contributors);
app.pkg.save();
cb();
});
});
});
function users(arr, cb) {
var acc = [];
each(arr, function(user, next) {
if (!user || !user.login) {
next(null, acc);
return;
}
github.get('/users/' + user.login, function(err, res) {
if (err) return next(err);
var contributor = { name: res.name };
var url = res.blog || res.html_url;
if (res.email) contributor.email = res.email;
if (url) contributor.url = url;
next(null, stringify(contributor));
});
}, cb);
}
};