UNPKG

clabot-fix

Version:

A bot to take the pain out of Contributor License Agreements

73 lines (67 loc) 2.18 kB
(function() { 'use strict'; var errorHandler, exports, github, _; _ = require('lodash'); github = require('@octokit/rest'); errorHandler = function(err, res) { var msg; msg = 'Fatal Error: GitHub refused to list Collaborators/Contributors'; console.log(msg); console.log(JSON.parse(err)); return res.send(500, msg); }; exports = module.exports = function(res, sender, options, contractors, msg, callback, payload) { var api, collabs, contribs, skip; api = new github({ version: '3.0.0', auth: options.token }); collabs = function(toBeSkipped, callback) { return api.repos.listCollaborators(msg, function(err, collaborators) { if (err) { errorHandler(err, res); } _.each(collaborators, function(collaborator) { return toBeSkipped.push(collaborator.login); }); return callback(toBeSkipped); }); }; contribs = function(toBeSkipped, callback) { return api.repos.listContributors(msg, function(err, contributors) { if (err) { errorHandler(err, res); } _.each(contributors, function(contributor) { return toBeSkipped.push(contributor.login); }); return callback(toBeSkipped); }); }; skip = function(toBeSkipped) { if (_.contains(toBeSkipped, sender)) { console.log('Skipping Collaborator/Contributor'); return res.send(200, 'Skipping Collaborator/Contributor'); } else { return callback(contractors); } }; if (options.skipCollaborators && options.skipContributors) { return collabs([], function(toBeSkipped) { return contribs(toBeSkipped, function(toBeSkipped) { return skip(toBeSkipped); }); }); } else if (options.skipCollaborators && !options.skipContributors) { return collabs([], function(toBeSkipped) { return skip(toBeSkipped); }); } else if (options.skipContributors) { return contribs([], function(toBeSkipped) { return skip(toBeSkipped); }); } else { return callback(contractors); } }; }).call(this);