From 38027e8dbe56e61608080cff0c1d98b77a7ea140 Mon Sep 17 00:00:00 2001 From: shel <2@shelru.ru> Date: Thu, 16 Apr 2020 15:57:00 +0400 Subject: [PATCH] Implemented multi reactions? --- index.js | 48 ++++++++++++++++++++++++++++++++++-------------- package.json | 2 +- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 7876357..6d8a7a3 100644 --- a/index.js +++ b/index.js @@ -14,18 +14,40 @@ const REACTION_TYPES = [ ]; async function addReaction(octokit, repo, comment_id, reactionType) { - if (REACTION_TYPES.includes(reactionType)) { - await octokit.reactions.createForIssueComment({ - owner: repo[0], - repo: repo[1], - comment_id: comment_id, - content: reactionType - }); - core.info(`Set '${reactionType}' reaction on comment.`); - } else { - core.setFailed("Invalid 'reaction-type'."); - return; - } + let ReactionsSet = [...new Set(reactionType.split(', ') + .filter(item => { + if(!REACTION_TYPES.includes(item)){ + core.info(`Skipping invalid 'reaction-type' '${item}'.`); + return false; + } + return true; + }))]; + + if(!ReactionsSet){ + core.setFailed(`Can't find any valid 'reaction-type' in provided value: ${reactionType}.`); + return false; + } + + let results = await Promise.allSettled(ReactionsSet.map(async (item) => { + await octokit.reactions.createForIssueComment({ + owner: repo[0], + repo: repo[1], + comment_id: comment_id, + content: item + }); + core.info(`Setting '${item}' reaction on comment.`); + })); + + for(let i = 0, l = results.length; i