Recently I needed to send emails to all contributors to my github project, so I wrote a little script in node.js (actually my first try was ruby, but have problems with https). Here is the script using only native modules:
#!/usr/bin/node
var https = require('https');
var path = require('path');
function get(host, path, callback) {
var options = {
host: host,
path: path,
headers: {
'User-Agent': 'Node.js' //required by github api
}
}
https.get(options, function(res) {
var output = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
output += chunk;
});
res.on('end', function() {
callback(JSON.parse(output));
});
});
}
if (process.argv.length == 4) {
var user = process.argv[2];
var repo = process.argv[3];
var path = '/repos/' + user + '/' + repo + '/contributors'
get('api.github.com', path, function(contributors) {
contributors.forEach(function(contributor) {
if (contributor.login != user) {
var path = contributor.url.replace(/https:\/\/[^\/]+/, '');
get('api.github.com', path, function(user) {
if (user.name) {
var email = user.email ? ' <' + user.email + '>' : '';
console.log(user.name + email);
}
});
}
});
});
} else {
console.log('usage: \n' + path.basename(process.argv[1]) + ' user repo');
}