|
| 1 | +name: Close Issues if Template Ignored |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [opened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + close_issues: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + steps: |
| 12 | + - name: Check issue body and creation date |
| 13 | + uses: actions/github-script@v6 |
| 14 | + with: |
| 15 | + script: | |
| 16 | + const issueBody = context.payload.issue.body; |
| 17 | + const issueNumber = context.payload.issue.number; |
| 18 | + const issueCreatedAt = new Date(context.payload.issue.created_at); |
| 19 | + const templateKeyword = "**Checklist "; // Change this to a unique part of your template |
| 20 | + |
| 21 | + // Define the cutoff date (year, month - 1, day) |
| 22 | + const cutoffDate = new Date(2024, 11, 2); // December is month 11 (0-based index) |
| 23 | + |
| 24 | + // Check if the issue was created after the cutoff date |
| 25 | + if (issueCreatedAt > cutoffDate) { |
| 26 | + // Check if the issue body contains the template keyword |
| 27 | + if (!issueBody.includes(templateKeyword)) { |
| 28 | + await github.rest.issues.createComment({ |
| 29 | + owner: context.repo.owner, |
| 30 | + repo: context.repo.repo, |
| 31 | + issue_number: issueNumber, |
| 32 | + body: "This issue does not follow the template and will be closed. Please update the issue following the template and reopen it." |
| 33 | + }); |
| 34 | + |
| 35 | + await github.rest.issues.update({ |
| 36 | + owner: context.repo.owner, |
| 37 | + repo: context.repo.repo, |
| 38 | + issue_number: issueNumber, |
| 39 | + state: "closed" |
| 40 | + }); |
| 41 | + } |
| 42 | + } |
0 commit comments