diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..1dd8aea --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,49 @@ +## What Changed? + + + +## Why? + + + +Closes #(issue number) + +## Type of Change + + + +- [ ] 🐛 Bug fix (fixes an issue without breaking existing functionality) +- [ ] ✨ New feature (adds new functionality without breaking existing features) +- [ ] 💥 Breaking change (existing functionality will be affected) +- [ ] 📝 Documentation update +- [ ] 🔧 Maintenance (refactoring, dependencies, configuration) + +## How Did You Test This? + + + +**What I tested:** + +- [ ] +- [ ] + +**How to test it:** + + + +1. +2. + +## Review Checklist + + + +- [ ] My code follows the project's style and conventions +- [ ] I've reviewed my own code for obvious issues +- [ ] I've added comments where the code might be confusing +- [ ] I've updated relevant documentation (if needed) +- [ ] I've tested my changes and they work as expected + +## Screenshots / Additional Context + + diff --git a/.github/workflows/pr-template-check.yml b/.github/workflows/pr-template-check.yml new file mode 100644 index 0000000..772233a --- /dev/null +++ b/.github/workflows/pr-template-check.yml @@ -0,0 +1,75 @@ +name: PR Template Check + +on: + pull_request: + types: [opened, edited, synchronize] + +jobs: + check-pr-description: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Check if PR description is filled out + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const prBody = context.payload.pull_request.body || ''; + + // Read the template file + const templatePath = '.github/pull_request_template.md'; + let template = ''; + try { + template = fs.readFileSync(templatePath, 'utf8'); + } catch (error) { + console.log('⚠️ Could not read template file, skipping template comparison'); + return; + } + + // Normalize whitespace for comparison + const normalizeText = (text) => text.replace(/\s+/g, ' ').trim(); + const normalizedPrBody = normalizeText(prBody); + const normalizedTemplate = normalizeText(template); + + // Check if PR body is identical to template + if (normalizedPrBody === normalizedTemplate) { + core.setFailed('❌ PR description is identical to the template. Please fill out the template with information about your changes.'); + return; + } + + // Check if PR body is empty or only contains whitespace + if (prBody.trim().length === 0) { + core.setFailed('❌ PR description is empty. Please fill out the template with information about your changes.'); + return; + } + + // Keywords that indicate the template hasn't been filled out + const templateKeywords = [ + 'Provide a clear summary of your changes', + 'What did you add, remove, or modify?', + 'Explain why these changes were needed', + 'Fixes #(issue number)', + ]; + + // Check if template keywords are still present (indicating it wasn't filled out) + const foundKeywords = templateKeywords.filter(keyword => + prBody.includes(keyword) + ); + + if (foundKeywords.length >= 2) { + core.setFailed( + `❌ PR template appears to be unfilled. Please replace the template text with your actual changes.\n\n` + + `Found unchanged template text:\n${foundKeywords.map(k => ` - "${k}"`).join('\n')}` + ); + return; + } + + // Check if "Fixes #(issue number)" is still present unchanged + if (prBody.includes('Fixes #(issue number)')) { + core.setFailed('❌ Please update "Fixes #(issue number)" with an actual issue number or remove it if not applicable.'); + return; + } + + console.log('✅ PR description appears to be properly filled out!');