ketan-clabot
Version:
A bot to take the pain out of Contributor License Agreements
78 lines (71 loc) • 2.42 kB
JavaScript
(function() {
'use strict';
var comment, exports, skip, status, _;
_ = require('lodash');
comment = require('./comment');
status = require('./status');
skip = require('./skip');
exports = module.exports = function(req, res, options, contractors, payload) {
var href, number, repo, sender, sha, user;
number = payload.number;
sender = payload.sender.login;
repo = payload.repository.name;
user = payload.repository.owner.login;
sha = payload.pull_request.head.sha;
href = payload.pull_request._links.html.href;
return skip(res, sender, options, contractors, {
user: user,
repo: repo
}, function(contractors) {
var callback, commentData, signed, statusData, success;
signed = _.contains(contractors, sender);
commentData = {
user: user,
repo: repo,
number: number
};
commentData.body = comment.getCommentBody(signed, options.templates, _.extend(options.templateData, {
sender: sender,
payload: payload
}));
success = true;
callback = _.after(2, function() {
if (!success) {
return res.send(500, "Fatal Error: GitHub refused to comment or create status");
} else {
return res.send(200, "Success: Comment and status created at " + href);
}
});
comment.send(options.token, commentData, function(err, data) {
if (err) {
success = false;
console.log(err);
console.log("Fatal Error: GitHub refused to comment");
} else {
href = payload.pull_request._links.html.href;
console.log("Success: Comment created at " + href);
}
return callback();
});
statusData = {
user: user,
repo: repo,
sha: sha
};
statusData.state = signed ? 'success' : 'pending';
statusData.description = signed ? 'CLA is signed' : 'CLA needs signing';
statusData.context = 'clabot';
statusData.target_url = options.templateData.link;
return status.set(options.token, statusData, function(err, data) {
if (err) {
success = false;
console.log(err);
console.log("Fatal Error: GitHub refused to create status");
} else {
console.log("Success: Status created at " + href);
}
return callback();
});
});
};
}).call(this);