diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fc89429..f40ca81 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ on: - reopened - opened workflow_dispatch: - push: { branches: ["main", "testing"] } + push: {branches: ["main", "testing", "check_assigned"]} jobs: close-multiple-issues: diff --git a/action.yml b/action.yml index 4f2ba50..4f98189 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,8 @@ inputs: gh-token: description: 'The GitHub token for authentication.' required: true + assign: + description: 'The issues that are assigned to the author' runs: using: 'node16' main: 'dist/index.js' diff --git a/src/index.ts b/src/index.ts index 7f03d52..1d2e6d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,7 +24,7 @@ async function HandleMultipleIssues() { // Retrieve custom inputs const label = core.getInput("label") || "multiple issues"; // Set default label - const labelInput = core.getInput("label"); + 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; @@ -43,14 +43,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 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); @@ -90,7 +100,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}`;