Skip to content

Commit 811c9b5

Browse files
Bullrichrzadp
andauthored
Added label filter (#18)
Added filter where a label is required for the issue to be considered. If the issue doesn't have the given label, it will filter it out. --------- Co-authored-by: Przemek Rzad <roopert7@gmail.com>
1 parent 2690d23 commit 811c9b5

File tree

7 files changed

+58
-5
lines changed

7 files changed

+58
-5
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ You can find all the inputs in [the action file](./action.yml) but let's walk th
7474
- It is **not** _case sensitive_.
7575
- It works great in conjuction with [`paritytech/list-team-members`](https://github.com/paritytech/list-team-members)
7676
- It can use the output directly to ignore any issues made by a member of a team.
77+
- `requiredLabels`: Collections of labels separated by commas that should be required when searching for a PR.
78+
- Only needs to have one of the included labels.
79+
- If you have labels: `A,B` the issue will be taken into consideration if it has: `A`, `B` or both `A` and `B`.
80+
- Short for `Only include issues with at least one of the required labels`.
81+
- **optional**
82+
- **Important**: If set be sure to connect the names by comma.
83+
- Example: `feature,bug,good first issue`
84+
- It is **not** _case sensitive_.
7785

7886
#### Accessing other repositories
7987

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ inputs:
2626
required: false
2727
description: Collections of usernames separated by commas that should be ignored if they are the author of the issue.
2828
type: string
29+
requiredLabels:
30+
required: false
31+
description: Collections of labels separated by commas that should be required when searching for a issue.
32+
type: string
2933
outputs:
3034
repo:
3135
description: 'The name of the repo in owner/repo pattern'
@@ -38,4 +42,4 @@ outputs:
3842

3943
runs:
4044
using: 'docker'
41-
image: 'docker://ghcr.io/paritytech/stale-issues-finder/action:0.0.6'
45+
image: 'docker://ghcr.io/paritytech/stale-issues-finder/action:0.1.0'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stale-issues-finder",
3-
"version": "0.0.6",
3+
"version": "0.1.0",
44
"description": "Find what issues have been stale for a given time",
55
"main": "src/index.ts",
66
"engines": {

src/filters.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ export const byNoComments = (issue: IssueData): boolean => issue.comments === 0;
77

88
export const isNotFromAuthor = ({ user }: IssueData, authors: string[]): boolean =>
99
!authors.some((author) => author.toLowerCase() === user?.login.toLowerCase());
10+
11+
export const byLabels = (issue: IssueData, requiredLabels: string[]): boolean =>
12+
issue.labels?.map((l) => l.name.toLowerCase()).some((l) => requiredLabels.map((lb) => lb.toLowerCase()).includes(l));

src/github/issuesParser.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,28 @@ const getAllIssues = async (octokit: InstanceType<typeof GitHub>, repo: Repo): P
2222
fullPage = data.length > 99;
2323
}
2424

25+
// parse the label data
26+
const parsedIssues = issues.map((issue) => {
27+
const labels: Label[] = [];
28+
for (const label of issue.labels) {
29+
let parsedLabel: Label;
30+
if (typeof label === "string") {
31+
parsedLabel = { id: 0, name: label, description: label, url: "" };
32+
} else {
33+
parsedLabel = {
34+
id: label.id ?? 0,
35+
name: label.name ?? "",
36+
description: label.description ?? "",
37+
url: label.url ?? "",
38+
};
39+
}
40+
labels.push(parsedLabel);
41+
}
42+
return { ...issue, labels };
43+
});
44+
2545
debug(`Found a total of ${issues.length} issues`);
26-
return issues;
46+
return parsedIssues;
2747
};
2848

2949
export const fetchIssues = async (octokit: InstanceType<typeof GitHub>, repo: Repo): Promise<IssueData[]> => {

src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { context, getOctokit } from "@actions/github";
33
import { Context } from "@actions/github/lib/context";
44
import moment from "moment";
55

6-
import { byNoComments, isNotFromAuthor, olderThanDays } from "./filters";
6+
import { byLabels, byNoComments, isNotFromAuthor, olderThanDays } from "./filters";
77
import { fetchIssues } from "./github/issuesParser";
88

99
const daysSinceDate = (date: string): number => moment().diff(moment(date), "days");
@@ -20,7 +20,13 @@ const getFiltersFromInput = (): Filters => {
2020
ignoreAuthors = authorsToIgnore.split(",");
2121
}
2222

23-
return { daysStale, noComments, notFromAuthor: ignoreAuthors };
23+
let requiredLabels: string[] = [];
24+
const labels = getInput("requiredLabels");
25+
if (labels) {
26+
requiredLabels = labels.split(",");
27+
}
28+
29+
return { daysStale, noComments, notFromAuthor: ignoreAuthors, requiredLabels };
2430
};
2531

2632
const generateMarkdownMessage = (issues: IssueData[], repo: { owner: string; repo: string }) => {
@@ -59,6 +65,9 @@ const filterIssues = (issues: IssueData[] | undefined, filters: Filters) => {
5965
if (filters.notFromAuthor.length > 0) {
6066
filteredData = filteredData.filter((is) => isNotFromAuthor(is, filters.notFromAuthor));
6167
}
68+
if (filters.requiredLabels?.length > 0) {
69+
filteredData = filteredData.filter((fd) => byLabels(fd, filters.requiredLabels));
70+
}
6271

6372
return filteredData;
6473
};

src/types/global.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ declare global {
88
comments: number;
99
/** If user was deleted it is going to be null */
1010
user: { login: string } | null;
11+
labels: Label[];
1112
}
1213

1314
interface Repo {
@@ -19,6 +20,14 @@ declare global {
1920
noComments?: boolean;
2021
daysStale: number;
2122
notFromAuthor: string[];
23+
requiredLabels: string[];
24+
}
25+
26+
interface Label {
27+
id: number;
28+
url: string;
29+
name: string;
30+
description: string;
2231
}
2332
}
2433

0 commit comments

Comments
 (0)