feat(rules): add repo_has_commits condition for the empty-repo case - #299
Open
CryptoJones wants to merge 1 commit into
Open
feat(rules): add repo_has_commits condition for the empty-repo case#299CryptoJones wants to merge 1 commit into
CryptoJones wants to merge 1 commit into
Conversation
A branch + PR presupposes a base to diff against. An initial commit into an
empty repo has none, so `no-direct-push-public-main` denied a push that had no
alternative route -- the only way to create the base is the push being blocked.
The workaround was to name each new repo in `except_repos`, repeated for every
new project, granting a permanent exemption to buy a one-time need.
`repo_has_commits` narrows the deny instead, so it applies once there is
history worth protecting:
when:
repo_visibility: public
branch: [main, master]
repo_has_commits: true
Two decisions worth stating, because both are easy to get subtly wrong.
It reads the REMOTE, not the local checkout. A push is always preceded by a
local commit, so a local probe reports "has commits" every time and the empty
case can never be observed. The probe is uncached: a repo goes from empty to
non-empty exactly once, and that single transition is the entire point, so a
stale entry would keep granting the exemption after the first commit landed.
It fails SAFE, opposite to repo_visibility. Visibility fails open to avoid
denying on a condition that could not be checked; here an undeterminable remote
must never widen an exemption, so unknown is treated as satisfying the
condition and the deny stands. Fail-open is wrong wherever a condition narrows
a deny rather than widening one.
Non-boolean values are rejected rather than coerced. A quoted "true" is a
string and would otherwise read as truthy; a block that silently flips a deny
is worse than one skipped and reported.
Tests cover both branches of the condition, the fail-safe path, boolean
validation, and the probe itself against a real local bare remote with a commit
present locally but not yet pushed -- the exact shape that makes a local-only
check useless. One test pins the behaviour that makes a typo dangerous: an
invalid block does not replace the seed rule, so the guard stays armed instead
of silently vanishing.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WxT7FQ4N46FE3Zn4uhQoa
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Team Run ID: 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 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
A branch + PR presupposes a base to diff against. An initial commit into an
empty repo has none, so
no-direct-push-public-maindenied a push that had noalternative route — the only way to create the base branch is the push being
blocked.
Hit for real today: a new public repo could not take its own first commit. The
available workaround was to add the repo to
except_repos, which has to berepeated for every new project and grants a permanent exemption to buy a
one-time need.
What
A
repo_has_commitscondition, so the deny can be narrowed to repos thatactually have history worth protecting:
Absent, nothing changes — existing rules keep their current behaviour.
Two decisions worth review
It reads the remote, not the local checkout. A push is always preceded by a
local commit, so a local probe reports "has commits" every time and the empty
case can never be observed. The probe is deliberately uncached: a repo goes
from empty to non-empty exactly once, and that single transition is the entire
point, so a stale entry would keep granting the exemption after the first
commit landed.
It fails safe, opposite to
repo_visibility. Visibility fails open toavoid denying on a condition that could not be checked. Here an undeterminable
remote must never widen an exemption, so unknown is treated as satisfying the
condition and the deny stands. Fail-open is wrong wherever a condition narrows
a deny rather than widening one.
Non-boolean values are rejected rather than coerced — a quoted
"true"is astring and would read as truthy, and a block that silently flips a deny is
worse than one that is skipped and reported.
Tests
9 added,
tests/test_rules.py20/20 green. Both branches of the condition, thefail-safe path, boolean validation,
format_rulesoutput, and the probe itselfagainst a real local bare remote with a commit present locally but not yet
pushed — the exact shape that makes a local-only check useless.
One test pins the behaviour that makes a typo dangerous: an invalid block does
not replace the seed rule, so the guard stays armed rather than silently
vanishing. That assertion was written after my first version of the test got it
backwards and the suite caught me.
Verification
tests/test_rules.py: 20 passedtests/test_server.py— confirmed identical on unmodifiedorigin/main(
1d2eac8) in a clean worktree, so they are not from this changeruff checkclean,ruff formatappliedProudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/