From 3d810287c03795f498443c74a489f787bcde670b Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 19 Apr 2018 14:38:09 +0200 Subject: [PATCH] Implement GitHub repo blacklist closes #17 --- integrations/github.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/integrations/github.js b/integrations/github.js index cdd4ed2..3ec47d4 100644 --- a/integrations/github.js +++ b/integrations/github.js @@ -5,6 +5,11 @@ module.exports = async function(robot, kredits) { robot.logger.debug('[hubot-kredits] Loading GitHub integration...'); + let repoBlackList = []; + if (process.env.KREDITS_GITHUB_REPO_BLACKLIST) { + repoBlackList = process.env.KREDITS_GITHUB_REPO_BLACKLIST.split(','); + robot.logger.debug('[hubot-kredits] Ignoring GitHub actions from ', util.inspect(repoBlackList)); + } const Contributor = kredits.Contributor; const Operator = kredits.Operator; @@ -15,7 +20,7 @@ module.exports = async function(robot, kredits) { return c.github_username === username; }); if (!contrib) { - throw new Error(`No contributor found for ${username}`);A + throw new Error(`No contributor found for ${username}`); } else { return contrib; } @@ -73,9 +78,15 @@ module.exports = async function(robot, kredits) { let web_url = issue.html_url; let amount = amountFromIssueLabels(issue); + let repoName = issue.repository_url.match(/.*\/(.+\/.+)$/)[1]; + let description = `${repoName}: ${issue.title}`; + if (amount === 0) { robot.logger.info('[hubot-kredits] Proposal amount from issue label is zero; ignoring'); return Promise.resolve(); + } else if (repoBlackList.includes(repoName)) { + robot.logger.debug(`[hubot-kredits] ${repoName} is on black list; ignoring`); + return Promise.resolve(); } if (assignees.length > 0) { @@ -84,9 +95,6 @@ module.exports = async function(robot, kredits) { recipients = [issue.user.login]; } - let repoName = issue.repository_url.match(/.*\/(.+\/.+)$/)[1]; - let description = `${repoName}: ${issue.title}`; - let proposalPromises = []; recipients.forEach(recipient => { proposalPromises.push( @@ -120,13 +128,17 @@ module.exports = async function(robot, kredits) { }) .then(issue => { let amount = amountFromIssueLabels(issue); - if (amount === 0) { - robot.logger.info('[hubot-kredits] Proposal amount from issue label is zero; ignoring'); - return; - } - let repoName = pull_request.base.repo.full_name; let description = `${repoName}: ${pull_request.title}`; + + if (amount === 0) { + robot.logger.info('[hubot-kredits] Proposal amount from issue label is zero; ignoring'); + return Promise.resolve(); + } else if (repoBlackList.includes(repoName)) { + robot.logger.debug(`[hubot-kredits] ${repoName} is on black list; ignoring`); + return Promise.resolve(); + } + let proposalPromises = []; recipients.forEach(recipient => { console.debug(`[hubot-kredits] Creating proposal for ${recipient}...`);