feat(branch): add require_description_grammar for strict branch descriptions - #581
shenxianpeng wants to merge 4 commits into
Conversation
… Branch validation conventional_branch checks the <type>/ prefix and accepts anything after the "/" as a bare ".+", so feature/Add_Login, fix/header_bug and release/v1.-2.0 all pass today although CC201's own error text names the Conventional Branch specification they violate. Add [branch] require_description_grammar, off by default, which also holds the description to the spec's grammar: lowercase alphanumeric segments joined by single hyphens, dots allowed inside a segment. With the option off the built regex is byte-for-byte what it was, so Dependabot's own grouped-update names (dependabot/npm_and_yarn/lodash-4.17.21) keep validating as before -- which is why this is opt-in rather than a tightening of the default. fix_branch_description() gives the failure a concrete correction when one is unambiguous (feature/Add_Login -> feature/add-login) and declines when it would be a guess (a second "/", shell punctuation, nothing left after stripping). BranchValidator composes it with fix_branch_type so a branch with both halves wrong gets one suggestion; the existing regex re-check still gates whether any suggestion is offered.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (11)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe pull request adds an opt-in ChangesBranch description grammar
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant CLIConfig
participant BranchValidator
participant fix_branch_description
participant BranchRegex
CLIConfig->>BranchValidator: provide require_description_grammar
BranchValidator->>fix_branch_description: normalize branch description
fix_branch_description-->>BranchValidator: return corrected description or None
BranchValidator->>BranchRegex: validate combined suggestion
BranchRegex-->>BranchValidator: accept or reject suggestion
Merge Risk: ⚪ Minimal · up to The opt-in grammar setting and branch rename suggestions behave as intended; no actionable merge risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 18.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 32 functions across 9 files. (2 skipped: 2 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #581 +/- ##
=======================================
Coverage 98.99% 99.00%
=======================================
Files 14 14
Lines 2198 2203 +5
=======================================
+ Hits 2176 2181 +5
Misses 22 22 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
`^[-.]+|[-.]+$` anchors each alternative on one side only, which is the shape of a mistake (Sonar S5850) even where it is deliberate. str.strip says the same thing plainly and drops a regex.
|
On CodeRabbit's Docstring Coverage pre-merge warning (18.75% vs an 80% threshold) — I checked it rather than waving it through, and I don't think it should start a change here. Of the 15 functions this PR adds, 14 are test methods and 1 is production code:
The one production function carries a full docstring. The percentage is driven entirely by test methods, and the files they land in are the ones that already document tests by class rather than by method — on The new tests follow that same shape: each new test class carries a docstring saying what it covers ( Happy to add them if you'd rather have the threshold satisfied — just say so. Generated by Claude Code |
Merging this PR will not alter performance
Comparing Footnotes
|
The option itself is a regex swap in the branch rule, plus the key, its CCHK_* variable and its flag. The rest of this PR had grown around it: - fix_branch_description, its composition with fix_branch_type in the branch validator and 76 lines of tests are gone. A rejected description now gets a suggestion that says what the description must look like, which is what a reader needs to fix it; an automatic rename can follow if people ask for one. - The README keeps one row in the configuration reference, which readme_test requires; the explanation belongs on commit-check.com with the rest of the reference, now that the README is a landing page. - The comments, the --help text and the copilot-instructions bullet are one line each. - The tests are one class: conformant names pass, non-conformant ones (Dependabot's grouped names among them) are rejected, the regex is byte-for-byte unchanged with the option off, allow_branch_names still readmits a bot, and the suggestion names the format.
|



Why
conventional_branchchecks the<type>/prefix and accepts anything after the/. Sofeature/Add_Login,feature/new--loginandfix/header_bugall pass, even though CC201's error text points at the spec they violate.What
This adds an opt-in
[branch] require_description_grammar, defaultfalse. When it is on, the description must also match the Conventional Branch grammar. The regex is the description part ofgrammar.regexin conventionalbranch.org'sspec.json: lowercase alphanumeric words joined by single hyphens, with dots allowed inside a word.It is off by default. Dependabot names its grouped updates like
dependabot/npm_and_yarn/lodash-4.17.21, with a second/and underscores, and the grammar rejects that. With the option off, the built regex is byte-for-byte the same as before. With it on,allow_branch_names = ["dependabot/.+"]orignore_authors = ["dependabot[bot]"]exempts the bot.Changes
rule_builder.py: the grammar constant, swapped in for.+when the option is on, plus a suggestion that describes the expected format.config_merger.pyandmain.py: the default,CCHK_REQUIRE_DESCRIPTION_GRAMMARand--require-description-grammar, like every other key.README.md: one row in the configuration reference, asreadme_testrequires. The full explanation will go on commit-check.com with the release..github/copilot-instructions.md: one bullet.Tests
TestBranchDescriptionGrammarchecks that:allow_branch_namesstill lets a bot through;The config merger tests cover the default, the env var and the flag. The full suite passes: 1112 tests. End to end,
feature/Add_Loginpasses by default, fails with the flag, andfeature/add-loginpasses with the env var.After release
commit-check.com's docs-sync test checks every runtime option against
configuration.md, so the site needs a row and a short section for this option in the same change that brings it to the released version.