Include main branch ruleset as part of the template#72
Conversation
Adapted from d-morrison/rpt#134. Exports the live `main` ruleset to .github/rulesets/main.json with the server-assigned fields stripped, adds apply-rulesets.sh that PUTs to update / POSTs to create (idempotent), and documents what's enforced in .github/rulesets/README.md. README.Rmd / README.md get a step pointing to the script under "Setup steps". qwt-specific ruleset: required PR + no force-push / no deletion + copilot code review on push, Maintain-role PR-only bypass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR packages the template repository’s default-branch protection ruleset into the template itself, along with tooling and documentation to apply and maintain it in newly created repos.
Changes:
- Adds an exported
mainbranch ruleset JSON under.github/rulesets/plus documentation for what it enforces and how to re-export it. - Introduces
.github/scripts/apply-rulesets.shto idempotently create/update rulesets in a target repo via the GitHub API. - Updates
README.Rmd/README.mdsetup steps to instruct users to apply the ruleset.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| README.Rmd | Adds setup-step documentation for applying rulesets. |
| README.md | Adds setup-step documentation for applying rulesets. |
| .github/scripts/apply-rulesets.sh | New script to create/update rulesets from JSON definitions. |
| .github/rulesets/README.md | Documents ruleset behavior and re-export process. |
| .github/rulesets/main.json | Exported ruleset definition for the default branch. |
|
@claude address review comments |
|
Claude finished @d-morrison's task in 2m 4s —— View job Addressed Review Comments
Changes made
Added # Before
existing=$(gh api "repos/$repo/rulesets" --jq '[.[] | {name, id}]')
# After
existing=$(gh api --paginate "repos/$repo/rulesets" --jq '[.[] | {name, id}]' | jq -s 'add // []')
Swapped steps 2 and 3 so users push their initial commit to
|
- Add --paginate to gh api rulesets call to avoid missing rulesets on repos with many rulesets, preventing spurious duplicates - Reorder setup steps: push to main before applying ruleset, since the ruleset blocks direct pushes after it is applied Co-authored-by: Douglas Ezra Morrison <d-morrison@users.noreply.github.com>
|
@claude fix failing workflows then iterate |
|
Claude finished @d-morrison's task in 3m 11s —— View job Fixed Failing Workflows
Cannot Fix — Workflow Permission Limitation
Committed: |
- Add "rulesets" to inst/WORDLIST (new word introduced by this PR) - Exclude quarto.org from lychee link checker (trusted docs site, unreachable from CI runners due to network restrictions) Co-authored-by: Douglas Ezra Morrison <d-morrison@users.noreply.github.com>
|
@claude review, then revise, iteratively |
|
Claude finished @d-morrison's task in 3m 40s —— View job Review & Revise
Summary of changes
# Find your ruleset ID:
gh api repos/OWNER/REPO/rulesets --jq '[.[] | {name, id}]'
Notes from the review
|
- Add .github/rulesets/ and apply-rulesets.sh to the project structure tree in README.Rmd and README.md - Add RULESET_ID discovery command before the re-export snippet in .github/rulesets/README.md so users know how to find the ID Co-authored-by: Douglas Ezra Morrison <d-morrison@users.noreply.github.com>
|
|
@claude review |
|
Claude finished @d-morrison's task in 1m 26s —— View job Code Review
Overall this PR is well-implemented. The previous iterations already addressed the Copilot review comments (pagination, step ordering). Here's a full review of the current state:
|
| Issue | Severity | |
|---|---|---|
main.json |
required_approving_review_count: 0 is undocumented — template users may not realize PRs need zero reviews |
Minor |
.github/rulesets/README.md |
bypass_mode: "pull_request" description is slightly misleading |
Minor |
.github/scripts/apply-rulesets.sh |
"Run once" comment is misleading for an idempotent script | Nit |
| Branch |
Adapted from d-morrison/rpt#134.
Summary
mainbranch ruleset to.github/rulesets/main.json(server-assigned fields stripped so it round-trips through the create/update endpoints)..github/scripts/apply-rulesets.shidempotently applies every JSON in.github/rulesets/to the current repo — PUT to update an existing ruleset by name, POST to create..github/rulesets/README.mddocuments what's enforced (required PR, no force-push / no deletion, copilot code review on push, Maintain-role PR-only bypass) and how to re-export after editing in the UI.README.Rmd/README.md: add a one-step entry under "Setup steps" pointing to the script.Test plan
.github/scripts/apply-rulesets.shagainst it — verify the ruleset shows up under Settings → Rules → Rulesets..github/rulesets/main.json, run the script, confirm the change appears in the GitHub UI.🤖 Generated with Claude Code