From 19077d62be52435a8a6a007475258a9082dcb903 Mon Sep 17 00:00:00 2001 From: Rob Dodson Date: Sat, 7 Mar 2020 10:02:40 -0800 Subject: [PATCH] Update comment first, then fallback to issue. --- index.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index e2938d35..e67274b9 100644 --- a/index.js +++ b/index.js @@ -55,26 +55,8 @@ async function run() { } const octokit = new github.GitHub(inputs.token); - - if (inputs.issueNumber) { - // Create a comment - if (!inputs.body) { - core.setFailed("Missing comment 'body'."); - return; - } - const { data: comment } = await octokit.issues.createComment({ - owner: repo[0], - repo: repo[1], - issue_number: inputs.issueNumber, - body: inputs.body - }); - core.info(`Created comment on issue '${inputs.issueNumber}'.`); - - // Set a comment reaction - if (inputs.reactionType) { - await addReaction(octokit, repo, comment.id, inputs.reactionType); - } - } else if (inputs.commentId) { + + if (inputs.commentId) { // Edit a comment if (!inputs.body && !inputs.reactionType) { core.setFailed("Missing either comment 'body' or 'reaction-type'."); @@ -108,6 +90,24 @@ async function run() { if (inputs.reactionType) { await addReaction(octokit, repo, inputs.commentId, inputs.reactionType); } + } else if (inputs.issueNumber) { + // Create a comment + if (!inputs.body) { + core.setFailed("Missing comment 'body'."); + return; + } + const { data: comment } = await octokit.issues.createComment({ + owner: repo[0], + repo: repo[1], + issue_number: inputs.issueNumber, + body: inputs.body + }); + core.info(`Created comment on issue '${inputs.issueNumber}'.`); + + // Set a comment reaction + if (inputs.reactionType) { + await addReaction(octokit, repo, comment.id, inputs.reactionType); + } } else { core.setFailed("Missing either 'issue-number' or 'comment-id'."); return;