From 9e7c8ca52c66aa3d004a9cd6a6c85004e7b4ce12 Mon Sep 17 00:00:00 2001 From: Amarnath Ravikumar Date: Wed, 26 Oct 2016 09:25:39 +0530 Subject: [PATCH] Allow withLabel to be an array --- README.md | 2 +- server.js | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5a79e1c..2f3f879 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ The bot can be configured by adding a `.mention-bot` file to the base directory "skipAlreadyMentionedPR": false, // mention-bot will ignore if there is already existing an exact mention "assignToReviewer": false, // mention-bot assigns the most appropriate reviewer for PR "skipTitle": "", // mention-bot will ignore PR that includes text in the title, - "withLabel": "", // mention-bot will only consider PR's with this label. Must set actions to ["labeled"]. + "withLabel": "", // Can either be a single label or a list. mention-bot will only consider PR's with any of the labels specified. Must set actions to ["labeled"]. "delayed": false, // mention-bot will wait to comment until specified time in `delayedUntil` value "delayedUntil": "3d", // Used if delayed is equal true, permitted values are: minutes, hours, or days, e.g.: '3 days', '40 minutes', '1 hour', '3d', '1h', '10m' "skipCollaboratorPR": false, // mention-bot will ignore if PR is made by collaborator diff --git a/server.js b/server.js index 40071c6..0c6f322 100644 --- a/server.js +++ b/server.js @@ -138,7 +138,7 @@ async function work(body) { withLabel: '', skipCollaboratorPR: false, }; - + if (process.env.MENTION_BOT_CONFIG) { try { repoConfig = { @@ -184,10 +184,20 @@ async function work(body) { return false; } - if (repoConfig.withLabel && data.label && - data.label.name != repoConfig.withLabel) { - console.log('Skipping because pull request does not have label: ' + repoConfig.withLabel); - return false; + const withLabel: Array | string = repoConfig.withLabel; + if (withLabel && data.label && data.label.name) { + if (typeof(withLabel) === 'array') { + if (withLabel.indexOf(data.label) === -1) { + console.log('Skipping because pull request does not ' + + 'have any of the labels: ' + withLabel.join(', ')); + return false; + } + } + else if (data.label.name != withLabel) { + console.log('Skipping because pull request does not have ' + + 'label: ' + withLabel); + return false; + } } if (repoConfig.skipTitle &&