-
-
Notifications
You must be signed in to change notification settings - Fork 50
46 lines (39 loc) · 1.63 KB
/
close-issues.yml
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
name: Close Issues if Template Ignored
on:
issues:
types: [opened]
permissions:
issues: write
contents: read
jobs:
close_issues:
runs-on: ubuntu-latest
steps:
- name: Check issue body and creation date
uses: actions/github-script@v6
with:
script: |
const issueBody = context.payload.issue.body;
const issueNumber = context.payload.issue.number;
const issueCreatedAt = new Date(context.payload.issue.created_at);
const templateKeyword = "**Checklist "; // Change this to a unique part of your template
// Define the cutoff date (year, month - 1, day)
const cutoffDate = new Date(2024, 11, 2); // December is month 11 (0-based index)
// Check if the issue was created after the cutoff date
if (issueCreatedAt > cutoffDate) {
// Check if the issue body contains the template keyword
if (!issueBody.includes(templateKeyword)) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: "This issue does not follow the template and will be closed. Please update the issue following the template and reopen it."
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: "closed"
});
}
}