From 5d76b2dead40bca322a8fb008460c49dbcadc06b Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 19 Apr 2018 11:34:47 +0200 Subject: [PATCH] Revert "minor refactorings" This reverts commit 8c481179b4387eb74b9584adf5cc189a5be5fcf3. --- index.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 225aa12..157ae9d 100644 --- a/index.js +++ b/index.js @@ -73,7 +73,9 @@ module.exports = async function(robot) { }); robot.respond(/propose (\d*)\s?\S*\s?to (\S+)(?:\sfor (.*))?$/i, res => { - let [_, amount, githubUser, description] = res.match; + let amount = res.match[1]; + let githubUser = res.match[2]; + let description = res.match[3]; let url = null; createProposal(githubUser, amount, description, url).then((result) => { messageRoom('Sounds good! Will be listed on https://kredits.kosmos.org in a bit...'); @@ -85,7 +87,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} ${proposal.description ? 'for ' + proposal.description : ''}`); + messageRoom(`* ${proposal.amount} kredits to ${contributor.name} for ${proposal.description}`); }); } }); @@ -130,8 +132,24 @@ 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; } - return { 'kredits-1': 50, 'kredits-2': 150, 'kredits-3': 500 }[kreditsLabel] || 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; } function handleGitHubIssueClosed(data) {