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
on:
issues:
types: [opened]
workflow_dispatch:
permissions:
issues: write
@@ -15,19 +14,26 @@ jobs:
uses: actions/github-script@v7
with:
script: |
const body = (context.payload.issue.body || "").toLowerCase();
const title = (context.payload.issue.title || "").toLowerCase();
const body = (context.payload.issue?.body || "").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
const usedTemplate = body.includes('netalertx_template');
// 2. Security Bypass: Don't close if it looks like a security report
const isSecurity = title.includes('security') || title.includes('vulnerability');
// 2. Security bypass
const isSecurity =
title.includes('security') ||
title.includes('vulnerability');
if (!usedTemplate && !isSecurity) {
const warningLabel = 'missing-template 📋';
// Add descriptive label
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
@@ -35,17 +41,15 @@ jobs:
labels: [warningLabel]
});
// Post polite comment with direct link to new issue
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 for your understanding! 🙏
Thank you! 🙏
`;
await github.rest.issues.createComment({
@@ -55,15 +59,9 @@ jobs:
body: commentMessage
});
// Close the issue (but do NOT lock it)
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
state: 'closed'
});
// Intentionally NOT closing issues in manual mode
console.log("Issue missing template labeled and commented.");
return;
}
console.log("Template detected or security keyword found ✅. Proceeding.");
console.log("Template detected or security issue no action taken.");