-
-
Notifications
You must be signed in to change notification settings - Fork 33
113 lines (97 loc) · 4.81 KB
/
Copy pathauto-close-issues.yml
File metadata and controls
113 lines (97 loc) · 4.81 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
name: Auto Close Invalid Issues
on:
issues:
types: [opened, edited]
permissions:
issues: write
jobs:
check-issue:
runs-on: ubuntu-latest
steps:
- name: Validate Issue Form and Content
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
if (!issue || issue.pull_request) return;
const body = issue.body || '';
// Check 1: Unchecked checkboxes (- [ ])
const hasUncheckedCheckboxes = /- \[\s*\]/.test(body);
// Check 2: Direct reference or topic match for items listed in issue #3
const bodyWithoutTemplateLabels = body
.replace(/I have read https:\/\/github\.com\/JoshAtticus\/Compressor\/issues\/3/gi, '')
.replace(/My issue is not listed in https:\/\/github\.com\/JoshAtticus\/Compressor\/issues\/3/gi, '')
.replace(/https:\/\/github\.com\/JoshAtticus\/Compressor\/issues\/3/gi, '');
const issue3TopicPatterns = [
/#3\b|issue\s*#?3\b|issues\/3\b/i,
// OEM-related WontFix
/in-app\s*(file\s*)?picker/i,
/file\s*browser/i,
/background\s*compress/i,
/background\s*encod/i,
/screen[\s-]off\s*encod/i,
/compress\s*(in\s*)?(the\s*)?background/i,
/save\s*to\s*photos/i,
/muxer\s*error/i,
// Out-of-scope features
/image\s*compress/i,
/photo\s*compress/i,
/compress(ing)?\s*(an?\s*)?(image|photo)s?/i,
/audio\s*compress/i,
/audio\s*extract/i,
/extract(ing)?\s*audio/i,
/compress(ing)?\s*audio/i,
/batch\s*(video\s*)?compress/i,
/bulk\s*(video\s*)?compress/i,
/compress(ing)?\s*multiple\s*video/i,
/video\s*to\s*gif/i,
/gif\s*convers/i,
/convert\s*(video\s*)?to\s*gif/i,
/crop(ping)?\s*video/i,
/trim(ming)?\s*video/i,
/video\s*crop/i,
/video\s*trim/i
];
const referencesIssue3 = issue3TopicPatterns.some(pattern => pattern.test(bodyWithoutTemplateLabels));
if (hasUncheckedCheckboxes || referencesIssue3) {
let reasonComment = 'This issue has been automatically closed as not planned because:\n';
if (hasUncheckedCheckboxes) {
reasonComment += '- Not all checkboxes in the prerequisites/disclaimer checklist were checked.\n';
}
if (referencesIssue3) {
reasonComment += '- It references or requests a topic listed in [issue #3](https://github.com/JoshAtticus/Compressor/issues/3) (OEM limitations / out-of-scope features).\n';
}
reasonComment += '\nPlease read the requirements and ensure your issue is not listed in [issue #3](https://github.com/JoshAtticus/Compressor/issues/3) before submitting.\n**Please do not worry if you think this is a mistake!** Your issue will still be reviewed by a maintainer and re-opened if it was incorrectly closed. **Do not open another issue.**';
// Post comment explaining closure
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: reasonComment
});
// Update labels: remove enhancement, triage, bug; add invalid, wontfix, and optionally "this person can't read"
const currentLabels = (issue.labels || []).map(l => (typeof l === 'string' ? l : l.name));
const labelsToRemove = new Set(['Enhancement', 'Triage', 'Bug']);
let updatedLabels = currentLabels.filter(name => !labelsToRemove.has(name));
updatedLabels.push("Invalid", "Won't Fix");
if (referencesIssue3) {
// updatedLabels.push("this person can't read");
// temporarily do nothing in this case
}
updatedLabels = Array.from(new Set(updatedLabels));
await github.rest.issues.setLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: updatedLabels
});
// Close issue as not_planned
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed',
state_reason: 'not_planned'
});
console.log(`Closed issue #${issue.number} as not_planned with labels: ${updatedLabels.join(', ')}.`);
}