diff --git a/action.yml b/action.yml index 71aaa47..c6cae7b 100644 --- a/action.yml +++ b/action.yml @@ -21,6 +21,10 @@ inputs: description: 'The GitHub token for authentication.' default: ${{ github.token }} required: false + assign: + description: 'To filter the issues that are assigned to the author' + default: 'false' + required: false runs: using: 'node16' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index 2227eca..4b17fd4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49,6 +49,7 @@ async function HandleMultipleIssues() { core.notice("step 1."); // Retrieve custom inputs const labels = core.getInput("label").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; @@ -62,12 +63,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 by 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) { @@ -102,7 +106,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 diff --git a/src/index.ts b/src/index.ts index db23c16..9786dc5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,6 +22,7 @@ async function HandleMultipleIssues() { // Retrieve custom inputs const labels = core.getInput("label").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; @@ -40,14 +41,24 @@ async function HandleMultipleIssues() { state: "open", }); - if (authorIssues.length === 0) { - core.notice("No existing open issues for this author."); - return; // No need to continue. - } + const filteredIssues = assign + ? authorIssues.filter((issue: any) => + issue.assignees.some((assignee: any) => assignee.login === author) + ) + : authorIssues + + if (filteredIssues.length === 0) { + core.notice( + `No existing ${ + assign === true ? "issues created by 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: { number: any }) => issue.number !== context.issue.number) // Exclude the current issue .map((issue: { number: any }) => issue.number); @@ -87,7 +98,9 @@ async function HandleMultipleIssues() { 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 commentText = `${issueLinks} ${comment}`; @@ -132,4 +145,4 @@ async function HandleMultipleIssues() { } } -HandleMultipleIssues(); +HandleMultipleIssues(); \ No newline at end of file