Updated the GitHub Actions workflow to enforce issue templates. Added handling for manual runs and improved comments.
This commit is contained in:
Jokob @NetAlertX
2026-01-27 22:17:29 +11:00
committed by GitHub
parent bc40ecd2c0
commit fed621f690

View File

@@ -1,8 +1,7 @@
name: Enforce Issue Templates name: Enforce Issue Templates
on: on:
issues: workflow_dispatch:
types: [opened]
permissions: permissions:
issues: write issues: write
@@ -15,19 +14,26 @@ jobs:
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
script: | script: |
const body = (context.payload.issue.body || "").toLowerCase(); const body = (context.payload.issue?.body || "").toLowerCase();
const title = (context.payload.issue.title || "").toLowerCase(); const title = (context.payload.issue?.title || "").toLowerCase();
// Manual runs don't have an issue context
if (!context.payload.issue) {
console.log("No issue context (manual run) nothing to enforce.");
return;
}
// 1. Check for template marker // 1. Check for template marker
const usedTemplate = body.includes('netalertx_template'); const usedTemplate = body.includes('netalertx_template');
// 2. Security Bypass: Don't close if it looks like a security report // 2. Security bypass
const isSecurity = title.includes('security') || title.includes('vulnerability'); const isSecurity =
title.includes('security') ||
title.includes('vulnerability');
if (!usedTemplate && !isSecurity) { if (!usedTemplate && !isSecurity) {
const warningLabel = 'missing-template 📋'; const warningLabel = 'missing-template 📋';
// Add descriptive label
await github.rest.issues.addLabels({ await github.rest.issues.addLabels({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
@@ -35,17 +41,15 @@ jobs:
labels: [warningLabel] labels: [warningLabel]
}); });
// Post polite comment with direct link to new issue
const commentMessage = ` const commentMessage = `
Hi there! 👋 Thanks for reaching out. Hi there! 👋 Thanks for reaching out.
To help the maintainers triage issues effectively, we **enforce the use of issue templates**. This helps us resolve problems much faster! To help the maintainers triage issues effectively, we **enforce the use of issue templates**.
**This issue has been closed** because it is missing the required template. Please [open a new issue here](https://github.com/${context.repo.owner}/${context.repo.repo}/issues/new/choose)
and select the appropriate template.
Please [open a new issue here](https://github.com/${context.repo.owner}/${context.repo.repo}/issues/new/choose) and select the appropriate template. Thank you! 🙏
Thank you for your understanding! 🙏
`; `;
await github.rest.issues.createComment({ await github.rest.issues.createComment({
@@ -55,15 +59,9 @@ jobs:
body: commentMessage body: commentMessage
}); });
// Close the issue (but do NOT lock it) // Intentionally NOT closing issues in manual mode
await github.rest.issues.update({ console.log("Issue missing template labeled and commented.");
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
state: 'closed'
});
return; return;
} }
console.log("Template detected or security keyword found ✅. Proceeding."); console.log("Template detected or security issue no action taken.");