diff --git a/dist/index.js b/dist/index.js index d922bfc..49e3a6c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -34,7 +34,6 @@ const core = __importStar(__nccwpck_require__(2186)); const github = __importStar(__nccwpck_require__(5438)); async function HandleMultipleIssues() { var _a; - console.log("Hello World!"); try { const token = core.getInput("gh-token"); if (!token) @@ -49,8 +48,10 @@ async function HandleMultipleIssues() { const context = github.context; core.notice("step 1."); // Retrieve custom inputs - const label = core.getInput("label") || "multiple issues"; // Set default label + // const label = core.getInput("label") || "multiple issues"; // Set default label const labelInput = core.getInput("label"); + const labels = labelInput.split(",").map(label => label.trim()); + const assign = core.getInput("assign") === "true" || false; const issueNumber = core.getInput("issueNumber") === "true" || false; // converts to boolean const comment = core.getInput("comment"); const close = core.getInput("close") === "true" || false; @@ -64,12 +65,15 @@ async function HandleMultipleIssues() { creator: author, state: "open", }); - if (authorIssues.length === 0) { - core.notice("No existing open issues for this author."); + const filteredIssues = assign + ? authorIssues.filter((issue) => issue.assignees.some((assignee) => assignee.login === author)) + : authorIssues; + if (filteredIssues.length === 0) { + core.notice(`No existing ${assign === true ? "issues created and assigned to" : "open issues for"} this author.`); return; // No need to continue. } core.notice("step 3."); - const previousIssueNumbers = authorIssues + const previousIssueNumbers = filteredIssues .filter((issue) => issue.number !== context.issue.number) // Exclude the current issue .map((issue) => issue.number); if (previousIssueNumbers.length > 0) { @@ -78,8 +82,8 @@ async function HandleMultipleIssues() { .map((issueNumber) => `#${issueNumber}`) .join(", "); // Check if label is an array and add multiple labels if needed - if (Array.isArray(label)) { - for (const lbl of label) { + if (Array.isArray(labels)) { + for (const lbl of labels) { await octokit.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, @@ -94,7 +98,7 @@ async function HandleMultipleIssues() { owner: context.repo.owner, repo: context.repo.repo, issue_number: issueNumberToLabel, - labels: [label], + labels: [labels], }); } core.notice("Labels added to issue #" + issueNumberToLabel); @@ -104,7 +108,10 @@ async function HandleMultipleIssues() { let commentText = ""; if (!checkComment) { // Condition 1: issueNumber is true, comment is false - commentText = `${issueLinks} is already opened by you.`; + if (assign) + commentText = `${issueLinks} has been opened by you and is also assigned to you.`; + else + commentText = `${issueLinks} is already opened by you.`; } else if (checkComment) { // Condition 2: issueNumber is true, comment is true