Skip to content

Add CI Check for Validating PR Template #9782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Validate cnames_active.js
name: Validate

on:
push:
Expand All @@ -7,12 +7,17 @@ on:
pull_request:
branches:
- master
types:
- opened
- reopened
- edited
- synchronize

permissions:
contents: read

jobs:
validate:
validate-cnames:
runs-on: ubuntu-latest

env:
Expand Down Expand Up @@ -41,3 +46,40 @@ jobs:
- name: Validate cnames_active.js
run: node index.js --validate ../cnames_active.js
working-directory: cleanup

validate-pr-template:
if: github.event_name == 'pull_request'

runs-on: ubuntu-latest

steps:
- name: Validate PR template
uses: actions/github-script@v7
with:
script: |
const body = context.payload.pull_request.body || "";

// 1. Check both checkboxes
const checkbox1 = /\[x\].*?There is reasonable content/i.test(body);
const checkbox2 = /\[x\].*?I have read and accepted/i.test(body);

// 2. URL must be on the exact "The site content can be seen at ..." line
const urlLineRegex = /^[ \t]*-[ \t]*The site content can be seen at[ \t]+(https?:\/\/[^\s]+)/m;
const urlMatch = urlLineRegex.exec(body);
const urlValid = urlMatch !== null;

// 3. Explanation must follow the blockquote marker
const explanationMatch = />\s*The site content is(?:\s*|\s*\n)(.+)/i.exec(body);
const explanation = explanationMatch && explanationMatch[1].trim().length > 10;

if (!checkbox1 || !checkbox2 || !urlValid || !explanation) {
core.setFailed(
"❌ PR template is not properly filled:\n" +
`Checkbox1: ${checkbox1 ? '✅' : '❌'}\n` +
`Checkbox2: ${checkbox2 ? '✅' : '❌'}\n` +
`URL on correct line: ${urlValid ? '✅' : '❌'}\n` +
`Explanation: ${explanation ? '✅' : '❌'}`
);
} else {
console.log("✅ PR template format is valid.");
}
Loading