forked from FuzzyGrim/Yamtrack
-
-
Notifications
You must be signed in to change notification settings - Fork 55
91 lines (79 loc) · 3.15 KB
/
Copy pathissue-title-check.yml
File metadata and controls
91 lines (79 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Issue title quality gate
on:
issues:
types: [opened, edited]
permissions:
issues: write
jobs:
check-title:
runs-on: ubuntu-latest
steps:
- name: Check issue title
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const title = issue.title.trim();
const labels = issue.labels.map(l => l.name);
const LABEL = "needs-title-fix";
// Strip known prefixes before evaluating
const normalized = title
.replace(/^\[(bug|feature request|enhancement|question)\]\s*/i, "")
.trim();
const words = normalized.split(/\s+/).filter(Boolean);
const BLACKLIST = /^(bug|bugs?|broken|error|issue|issues|problem|help|not working|crash|fix|request|feature)$/i;
const tooShort =
normalized.length < 20 ||
words.length < 4 ||
BLACKLIST.test(normalized);
if (!tooShort) {
// Title is fine — remove the label if it was previously flagged
if (labels.includes(LABEL)) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: LABEL,
});
}
return;
}
// Already commented? Don't spam — check existing comments
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
});
const alreadyCommented = comments.data.some(
c => c.user.login === "github-actions[bot]" &&
c.body.includes("needs-title-fix")
);
if (!alreadyCommented) {
const body = [
"Thanks for filing this! Before it can be triaged, the title needs to describe the actual problem.",
"",
"**Please edit the title** to be specific. Examples:",
"",
"- `[BUG] Metadata refresh fails silently for TVDB episodes`",
"- `[BUG] Watchlist import skips TMDB shows added before 2024`",
"- `[Feature Request] Add Storygraph import for reading history`",
"",
"Titles like `bug`, `missing watchlist`, or `metadata refresh bug` are too vague to scan or prioritize later.",
"",
"<!-- needs-title-fix -->",
].join("\n");
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body,
});
}
if (!labels.includes(LABEL)) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: [LABEL],
});
}