Skip to content

Commit

Permalink
chore: update the comment logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol-Baranwal committed Oct 14, 2023
1 parent 456bd70 commit 224cdd4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 22 additions & 10 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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({
Expand All @@ -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,
Expand Down

0 comments on commit 224cdd4

Please sign in to comment.