From 224cdd458b4e1a1f92b65aa9f097c9d15d4edae6 Mon Sep 17 00:00:00 2001 From: Anmol-Baranwal <74038190+Anmol-Baranwal@users.noreply.github.com> Date: Sun, 15 Oct 2023 03:25:14 +0530 Subject: [PATCH] chore: update the comment logic --- action.yml | 6 +++--- index.ts | 32 ++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/action.yml b/action.yml index 4701567..b3fb0d5 100644 --- a/action.yml +++ b/action.yml @@ -9,14 +9,14 @@ inputs: description: "Include issue number in the comment" required: false default: "false" - issueNumberComment: + comment: description: "Custom text to add after the issue number in the comment" required: false default: "false" - closeCurrent: + close: description: "Close the previous issue if set to true" required: false - default: "false" + default: "true" runs: using: "node20" main: "index.ts" diff --git a/index.ts b/index.ts index 1c724ca..a8ae09b 100644 --- a/index.ts +++ b/index.ts @@ -8,10 +8,10 @@ async function run() { const context = github.context; // Retrieve custom inputs - const label = core.getInput("label"); + const label = core.getInput("label") || "up for grabs"; // Set default label const issueNumber = core.getInput("issueNumber") === "true"; - const issueNumberComment = core.getInput("issueNumberComment"); - const closeCurrent = core.getInput("closeCurrent") === "true"; + const comment = core.getInput("comment"); + const close = core.getInput("close") === "true"; // Check if the same author has open issues const author = context.payload.issue.user.login; @@ -53,16 +53,17 @@ async function run() { core.notice("Labels added to issue #" + issueNumberToLabel); - // Add comments if issueNumber is true + // Add comments based on conditions if (issueNumber) { const issueLink = `#${issueNumberToLabel}`; let commentText: string; - if (issueNumberComment) { - // If issueNumberComment is provided, add it after the issue number. - commentText = `${issueLink} ${issueNumberComment}`; - } else { + if (!comment) { + // Condition 1: issueNumber is true, comment is false commentText = `${issueLink} is already opened by you.`; + } else if (comment) { + // Condition 2: issueNumber is true, comment is true + commentText = `#${issueNumberToLabel} ${comment}`; } await octokit.rest.issues.createComment({ @@ -72,11 +73,22 @@ async function run() { body: commentText, }); + core.notice("Comment added to issue #" + issueNumberToLabel); + } else if (!issueNumber && comment) { + // Condition 3: issueNumber is false, comment is true + + await octokit.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumberToLabel, + body: comment, + }); + core.notice("Comment added to issue #" + issueNumberToLabel); } - // Close the current issue if closeCurrent is true - if (closeCurrent && issueNumberToLabel === context.issue.number) { + // Close the current issue if close is true + if (close && issueNumberToLabel === context.issue.number) { await octokit.rest.issues.update({ owner: context.repo.owner, repo: context.repo.repo,