Skip to content

Commit a7491d6

Browse files
committed
Add triage fallback to label checker
1 parent 5be96a3 commit a7491d6

File tree

1 file changed

+75
-75
lines changed

1 file changed

+75
-75
lines changed

scripts/linters/labels.js

+75-75
Original file line numberDiff line numberDiff line change
@@ -6,101 +6,101 @@ const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
66
const { rest, paginate } = new Octokit({ auth: token });
77

88
const now = DateTime.now();
9-
const age = (timestamp) => now.diff(DateTime.fromISO(timestamp));
109

1110
(async () => {
1211
for await (const { data: issues } of paginate.iterator(
1312
rest.issues.listForRepo,
1413
{ owner, repo }
1514
)) {
16-
issues
17-
.filter(
18-
({ created_at }) => age(created_at) < Duration.fromObject({ years: 1 })
19-
)
20-
.forEach((issue) => {
21-
const { number, created_at, title, pull_request, html_url } = issue;
22-
const assignee = issue.assignee?.login;
15+
issues.forEach((issue) => {
16+
const { number, created_at, title, pull_request, html_url } = issue;
17+
const assignee = issue.assignee?.login;
2318

24-
const labels = issue.labels.map(({ name }) => name);
25-
const version = labels.find((name) => /\d+\.[\dx]+\.[\dx]+/.test(name));
19+
const age = now
20+
.diff(DateTime.fromISO(created_at))
21+
.shiftTo("years", "months", "days")
22+
.toHuman({ maximumFractionDigits: 0 });
2623

27-
const triaged = labels.includes("triage");
28-
const help = labels.includes("help wanted");
24+
const labels = issue.labels.map(({ name }) => name);
25+
const version = labels.find((name) => /\d+\.[\dx]+\.[\dx]+/.test(name));
2926

30-
const question = labels.includes("question");
31-
const unanswered = labels.includes("unanswered");
27+
const triage = labels.includes("triage");
28+
const help = labels.includes("help wanted");
3229

33-
const directions = labels.filter((i) =>
34-
["bug", "enhancement", "question"].includes(i)
35-
);
30+
const question = labels.includes("question");
31+
const unanswered = labels.includes("unanswered");
3632

37-
const problems = [];
33+
const directions = labels.filter((i) =>
34+
["bug", "enhancement", "question"].includes(i)
35+
);
3836

39-
if (directions.length === 0) {
40-
problems.push('Missing a "bug", "enhancement" or "question" label');
37+
const problems = [];
38+
39+
if (version) {
40+
if (assignee && help) {
41+
problems.push(
42+
'Should not have both an assignee and a "help wanted" label'
43+
);
4144
}
4245

43-
if (directions.length > 1) {
44-
problems.push('Too many "bug", "enhancement" and "question" labels');
46+
if (!assignee && !help) {
47+
problems.push('Missing an assignee or a "help wanted" label');
48+
}
49+
} else {
50+
if (assignee || help) {
51+
problems.push("Missing a version label");
4552
}
53+
}
4654

47-
if (version) {
48-
if (assignee && help) {
49-
problems.push(
50-
'Should not have both an assignee and a "help wanted" label'
51-
);
52-
}
53-
54-
if (!assignee && !help) {
55-
problems.push('Missing an assignee or a "help wanted" label');
56-
}
57-
} else {
58-
if (assignee || help) {
59-
problems.push("Missing a version label");
60-
}
55+
if (pull_request) {
56+
if (triage && version) {
57+
problems.push('Should not have both a "triage" and version label');
6158
}
6259

63-
if (pull_request) {
64-
if (triaged && version) {
65-
problems.push('Should not have both a "triage" and version label');
66-
}
67-
68-
if (!triaged && !version) {
69-
problems.push('Missing a "triage" or version label');
70-
}
71-
} else {
72-
if ([triaged, question, version].filter((i) => i).length > 1) {
73-
problems.push('Too many "triage", "question" and version labels');
74-
}
75-
76-
if ([triaged, question, version].every((i) => !i)) {
77-
problems.push('Missing a "triage", "question" or version label');
78-
}
60+
if (!triage && !version) {
61+
problems.push('Missing a "triage" or version label');
62+
}
63+
} else {
64+
if ([triage, question, version].filter((i) => i).length > 1) {
65+
problems.push('Too many "triage", "question" and version labels');
7966
}
8067

81-
if (problems.length > 0) {
82-
console.log({
83-
age: age(created_at)
84-
.shiftTo("years", "months", "days")
85-
.toHuman({ maximumFractionDigits: 0 }),
86-
source: {
87-
id: number,
88-
title,
89-
url: html_url,
90-
},
91-
problems,
92-
context: {
93-
labels,
94-
assignee,
95-
version,
96-
help_wanted: help,
97-
triaged,
98-
question,
99-
unanswered,
100-
directions,
101-
},
102-
});
68+
if ([triage, question, version].every((i) => !i)) {
69+
problems.push('Missing a "triage", "question" or version label');
70+
}
71+
}
72+
73+
if (!triage) {
74+
if (directions.length === 0) {
75+
problems.push('Missing a "bug", "enhancement" or "question" label');
76+
}
77+
78+
if (directions.length > 1) {
79+
problems.push('Too many "bug", "enhancement" and "question" labels');
10380
}
104-
});
81+
}
82+
83+
if (problems.length > 0) {
84+
console.log({
85+
age,
86+
source: {
87+
id: number,
88+
title,
89+
url: html_url,
90+
},
91+
problems,
92+
context: {
93+
labels,
94+
assignee,
95+
version,
96+
help_wanted: help,
97+
triage,
98+
question,
99+
unanswered,
100+
directions,
101+
},
102+
});
103+
}
104+
});
105105
}
106106
})();

0 commit comments

Comments
 (0)