-
Notifications
You must be signed in to change notification settings - Fork 0
Include main branch ruleset as part of the template #40
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
Open
d-morrison
wants to merge
7
commits into
main
Choose a base branch
from
claude/include-branch-ruleset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+201
−6
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
25e666e
feat: include main branch ruleset in template
d-morrison 5a14eee
fix: drop link-checker from required status checks
d-morrison 115c764
docs: drop stale link-checker mention from README setup step
d-morrison ae2874e
Address review nits on branch-ruleset template
d-morrison ca06859
Merge remote-tracking branch 'origin/main' into claude/include-branch…
claude eb28861
fix(spell): add 'rulesets' to WORDLIST
claude a99c62b
fix: address Copilot review findings on apply-rulesets.sh and docs
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Branch rulesets | ||
|
|
||
| Each JSON file here is a GitHub branch ruleset exported from the template's | ||
| canonical configuration. Apply them to a new repo (after creating it from | ||
| the template) with: | ||
|
|
||
| ```sh | ||
| .github/scripts/apply-rulesets.sh # current repo | ||
| .github/scripts/apply-rulesets.sh owner/repo # explicit target | ||
| ``` | ||
|
|
||
| The script is idempotent — re-running it updates a ruleset in place when | ||
| one with the same `name` already exists, rather than creating a duplicate. | ||
|
|
||
| Requirements: | ||
|
|
||
| - `gh` CLI authenticated as a repo admin (org or user). Branch rulesets | ||
| require admin scope to create. | ||
| - `jq` available on PATH. | ||
|
|
||
| ## What's enforced (`main.json`) | ||
|
|
||
| Applies to the default branch: | ||
|
|
||
| - **Required PR before merging** — no direct pushes to `main`. Note that | ||
| `required_approving_review_count` is `0`: a PR is required, but **zero | ||
| approvals** are needed, so authors can self-merge. This enforces process | ||
| (PR + status checks) but not peer review. Raise this value if you want to | ||
| require approvals before merge. | ||
| - **Required status checks** (not strict — branch does not need to be up | ||
| to date): Spellcheck, check-chars, build-deploy. The `build-deploy` | ||
| context is produced by `preview.yml` on PRs (publish.yml only runs on | ||
| push-to-main, so it can't satisfy this); if you rename either job, the | ||
| ruleset gate will hang. `check-links.yml` is intentionally excluded — it checks external URLs, | ||
| which can fail due to transient network issues or link rot unrelated to | ||
| the PR. Requiring it as a merge gate would block merges on external | ||
| failures outside the PR author's control. | ||
| - **No force-pushes, no branch deletion.** | ||
| - **Bypass** in `pull_request` mode for the Maintain role (role id 2) — | ||
| Maintainers can merge via a PR they authored, but cannot push directly. | ||
|
|
||
| ## Editing the ruleset | ||
|
|
||
| Edit `main.json` here, then run `apply-rulesets.sh` to push the change to | ||
| the live repo. Or edit in the GitHub UI (Settings → Rules → Rulesets) and | ||
| re-export with: | ||
|
|
||
| ```sh | ||
| # Find the ruleset ID: | ||
| RULESET_ID=$(gh api repos/OWNER/REPO/rulesets | jq '.[] | select(.name == "main") | .id') | ||
|
|
||
| gh api "repos/OWNER/REPO/rulesets/$RULESET_ID" \ | ||
| | jq 'del(.id, .node_id, .source, .source_type, .created_at, .updated_at, ._links, .current_user_can_bypass)' \ | ||
| > .github/rulesets/main.json | ||
| ``` | ||
|
|
||
| The fields stripped by `jq del(...)` are server-assigned and would either | ||
| be ignored or rejected by the create/update endpoints. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| { | ||
| "name": "main", | ||
| "target": "branch", | ||
| "enforcement": "active", | ||
| "conditions": { | ||
| "ref_name": { | ||
| "exclude": [], | ||
| "include": [ | ||
| "~DEFAULT_BRANCH" | ||
| ] | ||
| } | ||
| }, | ||
| "rules": [ | ||
| { | ||
| "type": "deletion" | ||
| }, | ||
| { | ||
| "type": "non_fast_forward" | ||
| }, | ||
| { | ||
| "type": "pull_request", | ||
| "parameters": { | ||
| "required_approving_review_count": 0, | ||
| "dismiss_stale_reviews_on_push": false, | ||
| "required_reviewers": [], | ||
| "require_code_owner_review": false, | ||
| "require_last_push_approval": false, | ||
| "required_review_thread_resolution": false, | ||
| "allowed_merge_methods": [ | ||
| "merge", | ||
| "squash", | ||
| "rebase" | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "type": "required_status_checks", | ||
| "parameters": { | ||
| "strict_required_status_checks_policy": false, | ||
| "do_not_enforce_on_create": false, | ||
| "required_status_checks": [ | ||
| { | ||
| "context": "Spellcheck", | ||
| "integration_id": 15368 | ||
| }, | ||
| { | ||
| "context": "check-chars", | ||
| "integration_id": 15368 | ||
| }, | ||
| { | ||
| "context": "build-deploy", | ||
| "integration_id": 15368 | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ], | ||
| "bypass_actors": [ | ||
| { | ||
| "actor_id": 2, | ||
| "actor_type": "RepositoryRole", | ||
| "bypass_mode": "pull_request" | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env bash | ||
| # Apply branch rulesets from .github/rulesets/*.json to the current repo. | ||
| # Run once after creating a new repo from this template. Idempotent: a | ||
| # ruleset whose `name` already exists on the repo is updated in place rather | ||
| # than duplicated. | ||
| # | ||
| # Requires: gh CLI authenticated with admin access to the repo. | ||
| # Usage: .github/scripts/apply-rulesets.sh [owner/repo] | ||
| # Defaults to the gh-detected current repo. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| command -v jq >/dev/null 2>&1 || { echo "error: jq is required but not found" >&2; exit 1; } | ||
|
d-morrison marked this conversation as resolved.
|
||
| command -v gh >/dev/null 2>&1 || { echo "error: gh is required but not found" >&2; exit 1; } | ||
|
|
||
| repo="${1:-$(gh repo view --json nameWithOwner -q .nameWithOwner)}" | ||
| ruleset_dir="$(cd "$(dirname "$0")/../rulesets" && pwd)" | ||
|
|
||
| shopt -s nullglob | ||
| files=("$ruleset_dir"/*.json) | ||
| if [ ${#files[@]} -eq 0 ]; then | ||
| echo "no rulesets found in $ruleset_dir" >&2 | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Map of existing ruleset name -> id, so we can PUT updates instead of | ||
| # creating duplicates. | ||
| existing=$(gh api --paginate "repos/$repo/rulesets" | jq -s '[.[][] | {name, id}]') | ||
|
|
||
| for f in "${files[@]}"; do | ||
| name=$(jq -r .name "$f") | ||
| if [ -z "$name" ] || [ "$name" = "null" ]; then | ||
| echo "skipping $f: missing .name field" >&2 | ||
| continue | ||
| fi | ||
| id=$(jq -r --arg n "$name" 'map(select(.name == $n)) | .[0].id // empty' <<<"$existing") | ||
| if [ -n "$id" ]; then | ||
| echo "updating ruleset '$name' (id $id) on $repo" | ||
| gh api -X PUT "repos/$repo/rulesets/$id" --input "$f" >/dev/null | ||
| else | ||
| echo "creating ruleset '$name' on $repo" | ||
| gh api -X POST "repos/$repo/rulesets" --input "$f" >/dev/null | ||
| fi | ||
| done | ||
|
|
||
| echo "done." | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,5 @@ emplate | |
| glitchy | ||
| lintr | ||
| ook | ||
| rulesets | ||
| uarto | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.