Ci/pr template validation#14
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds a GitHub Actions workflow that runs on pull request events and validates the PR body. It fails when the description is empty, still contains placeholder text, lacks a checked type-of-change item, or has no checked checklist items. ChangesPR template validation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/pr-template-validation.yml:
- Around line 64-69: The checklist validation in the PR template workflow is too
broad because the checked-box regex is matching any checkbox in the body,
including the required Type of Change section. Update the logic in the
workflow’s checklist check so it only scans the content under the ## Checklist
section before evaluating for at least one checked item, using the existing
validation block that sets checkedChecklist and errors.push. This should prevent
non-checklist selections from satisfying the requirement.
- Line 20: The workflow step using actions/github-script is not pinned to an
immutable revision, so update the uses reference in the GitHub Actions workflow
to a full commit SHA instead of `@v7`. Locate the github-script step in the
validation workflow and replace the version tag with the exact trusted commit
for actions/github-script.
- Around line 36-48: The PR template validation in the workflow only checks for
exact placeholder strings, so empty required sections can still pass. Update the
validation logic around the placeholder checks to also verify that the required
sections in the template such as Summary, What Changed?, and Testing contain
real user content, not just headings, separators, or stub bullets. Use the
existing validation flow in the workflow script to add section-level emptiness
checks alongside the current contains(placeholder) logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 38853f6e-c9ab-4728-a991-3a1409fc2ddb
📒 Files selected for processing (1)
.github/workflows/pr-template-validation.yml
|
|
||
| steps: | ||
| - name: Validate Pull Request Template | ||
| uses: actions/github-script@v7 |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== workflow ==\n'
cat -n .github/workflows/pr-template-validation.yml
printf '\n== pr template ==\n'
cat -n .github/PULL_REQUEST_TEMPLATE.md
printf '\n== pinning references ==\n'
rg -n "github-script@v7|pin.*SHA|full commit SHA|zizmor|actions/" .github README.md . || trueRepository: imuniqueshiv/HyperLearningTech
Length of output: 5070
Pin actions/github-script to a full commit SHA. Using @v7 leaves this guardrail exposed to upstream changes; pin the exact revision you intend to trust.
🧰 Tools
🪛 zizmor (1.26.1)
[error] 20-20: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)
(unpinned-uses)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/pr-template-validation.yml at line 20, The workflow step
using actions/github-script is not pinned to an immutable revision, so update
the uses reference in the GitHub Actions workflow to a full commit SHA instead
of `@v7`. Locate the github-script step in the validation workflow and replace the
version tag with the exact trusted commit for actions/github-script.
Source: Linters/SAST tools
| // Placeholder text must be removed | ||
| const placeholders = [ | ||
| "Provide a brief description of your changes.", | ||
| "Briefly describe the key changes made in this Pull Request.", | ||
| "Describe how you tested your changes.", | ||
| "Add any additional context for reviewers if needed." | ||
| ]; | ||
|
|
||
| for (const placeholder of placeholders) { | ||
| if (contains(placeholder)) { | ||
| errors.push(`Remove placeholder text: "${placeholder}"`); | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
This still allows empty required sections.
Right now the workflow only rejects the exact placeholder sentences. In the template, ## Summary, ## What Changed?, and ## Testing can still be left effectively blank by removing the placeholder text and keeping only the stub bullets/separators, so the “required sections are filled out” objective is not actually enforced.
Suggested direction
+ function getSection(title) {
+ return (
+ body.match(new RegExp(`## ${title}\\s*([\\s\\S]*?)(?:\\n---|\\n## |$)`, "i"))?.[1] ?? ""
+ );
+ }
+
+ function hasMeaningfulContent(text) {
+ return text
+ .replace(/^\s*-\s*$/gm, "")
+ .replace(/^\s*\*\*\*\s*$/gm, "")
+ .trim().length > 0;
+ }
+
+ for (const section of ["Summary", "What Changed\\?", "Testing"]) {
+ if (!hasMeaningfulContent(getSection(section))) {
+ errors.push(`Fill out the '${section.replace("\\?", "?")}' section.`);
+ }
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Placeholder text must be removed | |
| const placeholders = [ | |
| "Provide a brief description of your changes.", | |
| "Briefly describe the key changes made in this Pull Request.", | |
| "Describe how you tested your changes.", | |
| "Add any additional context for reviewers if needed." | |
| ]; | |
| for (const placeholder of placeholders) { | |
| if (contains(placeholder)) { | |
| errors.push(`Remove placeholder text: "${placeholder}"`); | |
| } | |
| } | |
| // Placeholder text must be removed | |
| const placeholders = [ | |
| "Provide a brief description of your changes.", | |
| "Briefly describe the key changes made in this Pull Request.", | |
| "Describe how you tested your changes.", | |
| "Add any additional context for reviewers if needed." | |
| ]; | |
| for (const placeholder of placeholders) { | |
| if (contains(placeholder)) { | |
| errors.push(`Remove placeholder text: "${placeholder}"`); | |
| } | |
| } | |
| function getSection(title) { | |
| return ( | |
| body.match(new RegExp(`## ${title}\\s*([\\s\\S]*?)(?:\\n---|\\n## |$)`, "i"))?.[1] ?? "" | |
| ); | |
| } | |
| function hasMeaningfulContent(text) { | |
| return text | |
| .replace(/^\s*-\s*$/gm, "") | |
| .replace(/^\s*\*\*\*\s*$/gm, "") | |
| .trim().length > 0; | |
| } | |
| for (const section of ["Summary", "What Changed\\?", "Testing"]) { | |
| if (!hasMeaningfulContent(getSection(section))) { | |
| errors.push(`Fill out the '${section.replace("\\?", "?")}' section.`); | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/pr-template-validation.yml around lines 36 - 48, The PR
template validation in the workflow only checks for exact placeholder strings,
so empty required sections can still pass. Update the validation logic around
the placeholder checks to also verify that the required sections in the template
such as Summary, What Changed?, and Testing contain real user content, not just
headings, separators, or stub bullets. Use the existing validation flow in the
workflow script to add section-level emptiness checks alongside the current
contains(placeholder) logic.
| // Require at least one checklist item to be checked | ||
| const checkedChecklist = | ||
| /\- \[x\]/i.test(body); | ||
|
|
||
| if (!checkedChecklist) { | ||
| errors.push("Complete the checklist before requesting review."); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Restrict the checklist regex to the ## Checklist section.
/\- \[x\]/i matches any checked box in the PR body, including the required Type of Change selection from .github/PULL_REQUEST_TEMPLATE.md. That means a PR with zero checklist items checked still passes once one change type is selected.
Suggested fix
- const checkedChecklist =
- /\- \[x\]/i.test(body);
+ const checklistSection =
+ body.match(/## Checklist\s*([\s\S]*?)(?:\n---|\n## |\s*$)/i)?.[1] ?? "";
+ const checkedChecklist = /\- \[x\]/i.test(checklistSection);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Require at least one checklist item to be checked | |
| const checkedChecklist = | |
| /\- \[x\]/i.test(body); | |
| if (!checkedChecklist) { | |
| errors.push("Complete the checklist before requesting review."); | |
| const checklistSection = | |
| body.match(/## Checklist\s*([\s\S]*?)(?:\n---|\n## |\s*$)/i)?.[1] ?? ""; | |
| const checkedChecklist = /\- \[x\]/i.test(checklistSection); | |
| if (!checkedChecklist) { | |
| errors.push("Complete the checklist before requesting review."); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/pr-template-validation.yml around lines 64 - 69, The
checklist validation in the PR template workflow is too broad because the
checked-box regex is matching any checkbox in the body, including the required
Type of Change section. Update the logic in the workflow’s checklist check so it
only scans the content under the ## Checklist section before evaluating for at
least one checked item, using the existing validation block that sets
checkedChecklist and errors.push. This should prevent non-checklist selections
from satisfying the requirement.
🎉 Congratulations @imuniqueshiv!Thank you for contributing to HyperLearningTech. Your pull request has been successfully merged into main. 📦 Merge Summary
🚀 Keep Contributing
Thank you for helping make HyperLearningTech better. Happy Coding! 🚀 |
Summary
Add automated validation for Pull Request templates to ensure contributors provide complete and meaningful PR descriptions before review.
Related Issue
N/A
Type of Change
What Changed?
Testing
Checklist
main.npm run format:checkpasses.npm run lintpasses.npm run typecheckpasses.npm run buildpasses.Additional Notes
This workflow improves contribution quality by enforcing a consistent Pull Request template while keeping issue references optional.
Summary by CodeRabbit