-
Notifications
You must be signed in to change notification settings - Fork 31
172 lines (140 loc) · 6.26 KB
/
version-check.yml
File metadata and controls
172 lines (140 loc) · 6.26 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Version Check Bot
on:
issues:
types: [opened, edited]
permissions:
issues: write
jobs:
check-version:
runs-on: ubuntu-latest
steps:
- name: Check version in issue title
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const title = issue.title;
// Regex to detect version pattern: optional v followed by numbers and dots
// Examples: v0.1.0, 0.0.4-alpha, v1.2.3-beta, [v0.1.0], [0.0.4-alpha], etc.
const versionRegex = /\[?v?\d+\.\d+(\.\d+)?(-[\w.]+)?\]?/i;
const hasVersion = versionRegex.test(title);
// Extract detected version for logging
const versionMatch = title.match(versionRegex);
const detectedVersion = versionMatch ? versionMatch[0] : null;
if (hasVersion) {
console.log(`Version detected in title: ${detectedVersion}`);
// Add a label to indicate version was detected
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['version-specified']
});
} catch (e) {
console.log('Could not add label (may not exist): ' + e.message);
}
// Remove warning label if it exists
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: 'missing-version'
});
} catch (e) {
// Label may not exist, that's fine
}
return;
}
// No version detected - warn the user
console.log('No version detected in title');
const warningMessage = `
## ⚠️ Version Required
Hello @${issue.user.login},
Thank you for your report! However, **your issue title is missing a version number**.
Please update your issue title to include the affected/target version in the format:
- \`[BUG] [v0.1.5] Your issue description\`
- \`[FEATURE] [v0.2.0] Your feature request\`
- \`[PERF] [v0.1.5] Your performance issue\`
**Examples of valid titles:**
- \`[BUG] [v0.1.5] CLI crashes on Windows\`
- \`[FEATURE] [v0.2.0] Add export functionality\`
Please edit your issue title to add the version. **Issues without a version will be automatically closed in 7 days.**
---
*This is an automated message. You can find your version by running \`[app cli --version]\`.*
`;
// Post warning comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: warningMessage
});
// Add warning label
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['missing-version']
});
} catch (e) {
console.log('Could not add label: ' + e.message);
}
close-stale-issues:
runs-on: ubuntu-latest
steps:
- name: Close issues without version after grace period
uses: actions/github-script@v7
with:
script: |
const sevenDaysAgo = new Date();
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
// Find issues with missing-version label
const { data: issues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: 'missing-version',
state: 'open'
});
const versionRegex = /\[?v?\d+\.\d+(\.\d+)?(-[\w.]+)?\]?/i;
for (const issue of issues) {
const createdAt = new Date(issue.created_at);
// Skip if issue was created less than 7 days ago
if (createdAt > sevenDaysAgo) {
console.log(`Issue #${issue.number} is too recent, skipping`);
continue;
}
// Double-check title still doesn't have version
if (versionRegex.test(issue.title)) {
console.log(`Issue #${issue.number} now has version, removing label`);
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: 'missing-version'
});
} catch (e) {}
continue;
}
// Close the issue
console.log(`Closing issue #${issue.number} - no version after 7 days`);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `## Issue Closed
This issue has been automatically closed because no version was specified in the title after 7 days.
If you still want to report this issue, please create a new issue with the version included in the title (e.g., \`[BUG] [v0.1.5] Your description\`).
Thank you for your understanding.`
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed',
state_reason: 'not_planned'
});
}