Skip to content

Commit

Permalink
feat: add option to get issues assigned to author
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol-Baranwal committed Nov 14, 2023
1 parent e6c4aad commit 634cefb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- reopened
- opened
workflow_dispatch:
push: { branches: ["main", "testing"] }
push: {branches: ["main", "testing", "check_assigned"]}

jobs:
close-multiple-issues:
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
26 changes: 19 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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}`;
Expand Down

0 comments on commit 634cefb

Please sign in to comment.