2024-03-22 19:43:17 +08:00
name : Issue Template Checks
on :
2024-05-02 01:13:18 +08:00
workflow_dispatch :
2024-03-22 19:43:17 +08:00
jobs :
check-required-fields :
runs-on : ubuntu-latest
steps :
- name : Checkout repository
uses : actions/checkout@v2
- name : Comment on Issues Missing Required Fields
uses : actions/github-script@v6
with :
script : |
const issue = context.payload.issue;
const issueLabels = issue.labels.map(label => label.name);
const hasRelevantLabel = issueLabels.includes('failed-test') || issueLabels.includes('verified-test');
// Proceed only if the issue has a relevant label
if (!hasRelevantLabel) {
console.log("Issue does not have relevant labels. Skipping.");
return;
}
const requiredFields = [
"Browser:" ,
"OS:" ,
"Adblock Solution" ,
"Description of Issue:" ,
"Test Result:" ,
] ;
2024-03-22 21:36:24 +08:00
// Helper function to check if a required field is actually filled
2024-03-22 19:43:17 +08:00
const isFieldMissing = (field) => {
2024-03-22 21:36:24 +08:00
// Regex to find the field and any subsequent text
const fieldRegex = new RegExp(`${field}\\s*:\\s*(.+)`);
const match = issue.body.match(fieldRegex);
// Check if the field is present and has content after the colon
return !match || match[1].trim().length === 0;
2024-03-22 19:43:17 +08:00
};
// Find all missing fields
const missingFields = requiredFields.filter(isFieldMissing);
// If there are missing fields, post a comment
if (missingFields.length > 0) {
const commentBody = `Hello @${issue.user.login}, it looks like your issue is missing some required information: \n- ${missingFields.join("\n- ")}\nPlease update your issue to include this information.`;
await github.rest.issues.createComment({
issue_number : issue.number,
owner : context.repo.owner,
repo : context.repo.repo,
body : commentBody
});
} else {
console.log("Issue contains all required fields.");
}