Skip to content

Commit

Permalink
feat: add option to filter issues assigned to author
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol-Baranwal committed Nov 15, 2023
1 parent 6964518 commit cbfd318
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
15 changes: 11 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
27 changes: 20 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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}`;
Expand Down Expand Up @@ -132,4 +145,4 @@ async function HandleMultipleIssues() {
}
}

HandleMultipleIssues();
HandleMultipleIssues();

0 comments on commit cbfd318

Please sign in to comment.