feat(pr-checklist): make checklist validation conditional for history-rewrite related PRs

This commit is contained in:
GitHub Actions
2025-12-09 02:42:37 +00:00
parent 1adbd0aba4
commit b20a38e980
2 changed files with 24 additions and 7 deletions

View File

@@ -6,20 +6,36 @@ on:
jobs:
validate:
name: Validate history-rewrite checklist
name: Validate history-rewrite checklist (conditional)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate PR checklist
- name: Validate PR checklist (only for history-rewrite changes)
uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.get({owner: context.repo.owner, repo: context.repo.repo, pull_number: context.issue.number});
const owner = context.repo.owner;
const repo = context.repo.repo;
const prNumber = context.issue.number;
const pr = await github.rest.pulls.get({owner, repo, pull_number: prNumber});
const body = (pr.data && pr.data.body) || '';
const required = [ 'preview_removals.sh', 'data/backups', 'I will not run the destructive --force' ];
for (const r of required) {
if (!body.toLowerCase().includes(r.toLowerCase())) { core.setFailed('Missing required checklist item: '+r); return; }
// Determine if this PR modifies history-rewrite related files
const filesResp = await github.rest.pulls.listFiles({ owner, repo, pull_number: prNumber });
const files = filesResp.data.map(f => f.filename.toLowerCase());
const relevant = files.some(fn => fn.startsWith('scripts/history-rewrite/') || fn.startsWith('docs/plans/history_rewrite.md') || fn.includes('history-rewrite'));
if (!relevant) {
core.info('No history-rewrite related files changed; skipping checklist validation.');
return;
}
const required = [ 'preview_removals.sh', 'data/backups', "i will not run the destructive --force" ];
const missing = required.filter(r => !body.toLowerCase().includes(r.toLowerCase()));
if (missing.length > 0) {
// Post a comment to the PR with instructions for filling the checklist
const commentBody = `Hi! This PR touches history-rewrite artifacts and requires the checklist in .github/PULL_REQUEST_TEMPLATE/history-rewrite.md. The following items are missing in your PR body: ${missing.join(', ')}\n\nPlease update the PR description using the history-rewrite template and re-run checks.`;
await github.rest.issues.createComment({ owner, repo, issue_number: prNumber, body: commentBody });
core.setFailed('Missing required checklist items: ' + missing.join(', '));
}
core.info('PR checklist looks good');

View File

@@ -81,3 +81,4 @@ CI automation
-------------
- A CI dry-run workflow `.github/workflows/dry-run-history-rewrite.yml` runs a non-destructive check that fails CI when banned history entries or large objects are found. It is triggered on PRs and a daily schedule.
- A PR checklist template `.github/PULL_REQUEST_TEMPLATE/history-rewrite.md` and a checklist validator `.github/workflows/pr-checklist.yml` ensure contributors attach the preview output and backups before seeking approval.
- The PR checklist validator is conditional: it only enforces the checklist when the PR modifies `scripts/history-rewrite/*`, `docs/plans/history_rewrite.md`, or similar history-rewrite related files. This avoids blocking unrelated PRs.