Skip to content

Commit cbfd318

Browse files
feat: add option to filter issues assigned to author
1 parent 6964518 commit cbfd318

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ inputs:
2121
description: 'The GitHub token for authentication.'
2222
default: ${{ github.token }}
2323
required: false
24+
assign:
25+
description: 'To filter the issues that are assigned to the author'
26+
default: 'false'
27+
required: false
2428
runs:
2529
using: 'node16'
2630
main: 'dist/index.js'

dist/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ async function HandleMultipleIssues() {
4949
core.notice("step 1.");
5050
// Retrieve custom inputs
5151
const labels = core.getInput("label").split(",").map(label => label.trim());
52+
const assign = core.getInput("assign") === "true" || false;
5253
const issueNumber = core.getInput("issueNumber") === "true" || false; // converts to boolean
5354
const comment = core.getInput("comment");
5455
const close = core.getInput("close") === "true" || false;
@@ -62,12 +63,15 @@ async function HandleMultipleIssues() {
6263
creator: author,
6364
state: "open",
6465
});
65-
if (authorIssues.length === 0) {
66-
core.notice("No existing open issues for this author.");
66+
const filteredIssues = assign
67+
? authorIssues.filter((issue) => issue.assignees.some((assignee) => assignee.login === author))
68+
: authorIssues;
69+
if (filteredIssues.length === 0) {
70+
core.notice(`No existing ${assign === true ? "issues created by and assigned to" : "open issues for"} this author.`);
6771
return; // No need to continue.
6872
}
6973
core.notice("step 3.");
70-
const previousIssueNumbers = authorIssues
74+
const previousIssueNumbers = filteredIssues
7175
.filter((issue) => issue.number !== context.issue.number) // Exclude the current issue
7276
.map((issue) => issue.number);
7377
if (previousIssueNumbers.length > 0) {
@@ -102,7 +106,10 @@ async function HandleMultipleIssues() {
102106
let commentText = "";
103107
if (!checkComment) {
104108
// Condition 1: issueNumber is true, comment is false
105-
commentText = `${issueLinks} is already opened by you.`;
109+
if (assign)
110+
commentText = `${issueLinks} has been opened by you and is also assigned to you.`;
111+
else
112+
commentText = `${issueLinks} is already opened by you.`;
106113
}
107114
else if (checkComment) {
108115
// Condition 2: issueNumber is true, comment is true

src/index.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ async function HandleMultipleIssues() {
2222

2323
// Retrieve custom inputs
2424
const labels = core.getInput("label").split(",").map(label => label.trim());
25+
const assign = core.getInput("assign") === "true" || false;
2526
const issueNumber = core.getInput("issueNumber") === "true" || false; // converts to boolean
2627
const comment = core.getInput("comment");
2728
const close = core.getInput("close") === "true" || false;
@@ -40,14 +41,24 @@ async function HandleMultipleIssues() {
4041
state: "open",
4142
});
4243

43-
if (authorIssues.length === 0) {
44-
core.notice("No existing open issues for this author.");
45-
return; // No need to continue.
46-
}
44+
const filteredIssues = assign
45+
? authorIssues.filter((issue: any) =>
46+
issue.assignees.some((assignee: any) => assignee.login === author)
47+
)
48+
: authorIssues
49+
50+
if (filteredIssues.length === 0) {
51+
core.notice(
52+
`No existing ${
53+
assign === true ? "issues created by and assigned to" : "open issues for"
54+
} this author.`
55+
)
56+
return // No need to continue.
57+
}
4758

4859
core.notice("step 3.");
4960

50-
const previousIssueNumbers = authorIssues
61+
const previousIssueNumbers = filteredIssues
5162
.filter((issue: { number: any }) => issue.number !== context.issue.number) // Exclude the current issue
5263
.map((issue: { number: any }) => issue.number);
5364

@@ -87,7 +98,9 @@ async function HandleMultipleIssues() {
8798

8899
if (!checkComment) {
89100
// Condition 1: issueNumber is true, comment is false
90-
commentText = `${issueLinks} is already opened by you.`;
101+
102+
if(assign) commentText = `${issueLinks} has been opened by you and is also assigned to you.`;
103+
else commentText = `${issueLinks} is already opened by you.`;
91104
} else if (checkComment) {
92105
// Condition 2: issueNumber is true, comment is true
93106
commentText = `${issueLinks} ${comment}`;
@@ -132,4 +145,4 @@ async function HandleMultipleIssues() {
132145
}
133146
}
134147

135-
HandleMultipleIssues();
148+
HandleMultipleIssues();

0 commit comments

Comments
 (0)