From 8c481179b4387eb74b9584adf5cc189a5be5fcf3 Mon Sep 17 00:00:00 2001 From: bumi Date: Thu, 19 Apr 2018 01:01:26 +0200 Subject: [PATCH] minor refactorings --- index.js | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index dc7e4ae..8f20c53 100644 --- a/index.js +++ b/index.js @@ -72,9 +72,7 @@ module.exports = async function(robot) { }); robot.respond(/propose (\d*)\s?\S*\s?to (\S+)(?:\sfor (.*))?$/i, res => { - let amount = res.match[1]; - let githubUser = res.match[2]; - let description = res.match[3]; + let [_, amount, githubUser, description] = res.match; let url = null; createProposal(githubUser, amount, description, url).then((result) => { messageRoom('Sounds good! Will be listed on https://kredits.kosmos.org in a bit...'); @@ -86,7 +84,7 @@ module.exports = async function(robot) { proposals.forEach((proposal) => { if (!proposal.executed) { Contributor.getById(proposal.contributorId).then((contributor) => { - messageRoom(`* ${proposal.amount} kredits to ${contributor.name} for ${proposal.description}`); + messageRoom(`* ${proposal.amount} kredits to ${contributor.name} ${proposal.description ? 'for ' + proposal.description : ''}`); }); } }); @@ -131,24 +129,8 @@ module.exports = async function(robot) { function amountFromIssueLabels(issue) { let kreditsLabel = issue.labels.map(l => l.name) .filter(n => n.match(/^kredits/))[0]; - // No label, no kredits - if (typeof kreditsLabel === 'undefined') { return 0; } - // TODO move to config maybe? - let amount; - switch(kreditsLabel) { - case 'kredits-1': - amount = 50; - break; - case 'kredits-2': - amount = 150; - break; - case 'kredits-3': - amount = 500; - break; - } - - return amount; + return { 'kredits-1': 50, 'kredits-2': 150, 'kredits-3': 500 }[kreditsLabel] || 0 } function handleGitHubIssueClosed(data) {