Skip to content

Conversation

@shenxianpeng
Copy link
Contributor

@shenxianpeng shenxianpeng commented Dec 15, 2025

closes #335

Summary by CodeRabbit

  • New Features

    • Added configuration option to specify additional custom branch names allowed when using conventional branch validation rules.
  • Documentation

    • Updated configuration documentation with details and examples for the new branch name allowlist feature.

✏️ Tip: You can customize this high-level summary in your review settings.

@shenxianpeng shenxianpeng requested a review from a team as a code owner December 15, 2025 18:50
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 15, 2025

Walkthrough

This PR adds support for user-configurable allowed branch names beyond the conventional branch pattern. Users can now add custom branch names (like "develop" or "staging") via an allow_branch_names configuration option, which are incorporated into the validation regex pattern during rule building.

Changes

Cohort / File(s) Summary
Core functionality
commit_check/__init__.py, commit_check/rule_builder.py
Added DEFAULT_BRANCH_NAMES constant export; introduced _get_allowed_branch_names() method to deduplicate and preserve order; updated _build_conventional_branch_regex signature to accept allowed_names parameter; modified _build_conventional_branch_rule to retrieve and pass allowed branch names to regex builder.
Configuration & suggestions
commit_check/rules_catalog.py, docs/configuration.rst
Updated BRANCH_RULES suggestion text to mention allow_branch_names config option; added allow_branch_names documentation as an optional list field with default empty list under branch options.
Test coverage
tests/engine_test.py
Added tests validating that custom branches (develop, staging) are allowed when included in the validation regex and blocked when excluded.
Rule builder tests
tests/rule_builder_test.py
Added comprehensive test suite covering default branch names, custom branch names, empty lists, and deduplication behavior of allow_branch_names.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

  • Regex construction logic: Verify that _build_conventional_branch_regex correctly combines default names (master, main, HEAD, PR-.+) with custom allowed_names and produces valid regex patterns
  • Deduplication method: Ensure _get_allowed_branch_names properly handles duplicates while preserving insertion order
  • Test assertions: Confirm all test cases in rule_builder_test.py accurately validate regex construction and that engine_test.py covers the full allowed/blocked branch scenarios

Possibly related PRs

Suggested labels

developer

Poem

A rabbit hops through branches wide,
"Develop" now may be our guide!
With "staging" too, no more we fret,
Conventional rules with flexibility yet! 🐰✨
Custom names in config set,
The branch validation debt is met!

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding support for an allow_branch_names configuration option.
Linked Issues check ✅ Passed The PR fully implements the objective from issue #335 by adding a new allow_branch_names configuration option that allows users to specify additional branch names (like develop) that should pass the branch check, directly addressing the reporter's need.
Out of Scope Changes check ✅ Passed All changes are focused on implementing the allow_branch_names feature across configuration, rule building, validation, and tests with no unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/issue-335

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added bug Something isn't working documentation Improvements or additions to documentation labels Dec 15, 2025
@netlify
Copy link

netlify bot commented Dec 15, 2025

Deploy Preview for commit-check ready!

Name Link
🔨 Latest commit 4d84083
🔍 Latest deploy log https://app.netlify.com/projects/commit-check/deploys/694058905e49280008679f86
😎 Deploy Preview https://deploy-preview-336--commit-check.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@shenxianpeng shenxianpeng removed the bug Something isn't working label Dec 15, 2025
@shenxianpeng shenxianpeng requested a review from Copilot December 15, 2025 18:51
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 15, 2025

Quality Gate Passed Quality Gate passed

Issues
0 New issues
4 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.46%. Comparing base (996758d) to head (4d84083).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #336      +/-   ##
==========================================
+ Coverage   87.17%   87.46%   +0.29%     
==========================================
  Files           8        8              
  Lines         686      694       +8     
==========================================
+ Hits          598      607       +9     
+ Misses         88       87       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shenxianpeng shenxianpeng added the minor A minor version bump label Dec 15, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/engine_test.py (1)

194-201: Add an assertion in test_validate_with_stdin_text

This test currently just calls validator.validate(context) without asserting the result. To make it a meaningful regression guard, assert the expected outcome, e.g.:

result = validator.validate(context)
assert result == ValidationResult.PASS

Right now it only verifies “no exception raised”.

🧹 Nitpick comments (4)
commit_check/__init__.py (1)

44-45: Check Python version support for list[str] annotation

If this project still supports Python 3.8 or lower, list[str] will be invalid syntax at runtime. In that case, either:

  • Switch to from typing import List and DEFAULT_BRANCH_NAMES: List[str] = [], or
  • Add from __future__ import annotations at the top of the module.

Also consider using a tuple for the default (DEFAULT_BRANCH_NAMES: List[str] = [] used only as a default and never mutated, but a tuple or explicit copy when reading can make that intent clearer).

commit_check/rules_catalog.py (1)

115-115: Branch rule suggestion text is accurate; consider minor wording tweak

The updated suggest message correctly mentions allow_branch_names and ignore_authors as configuration options. To tighten readability, you might slightly rephrase, e.g.:

"Use <type>/<description> with allowed types, or add the branch name to [branch].allow_branch_names in config. To bypass this check entirely for certain authors, configure [branch].ignore_authors."

Purely a clarity/wording suggestion; behavior is fine.

tests/engine_test.py (1)

202-260: BranchValidator tests for develop/staging correctly capture new behavior

The new tests for develop/staging:

  • Correctly mock has_commits and get_branch_name.
  • Use regexes that explicitly include or exclude those branch names to assert PASS/FAIL behavior.

This aligns with the new allow_branch_names-driven regex behavior in RuleBuilder. If you later refactor the branch regex shape, consider centralizing the pattern (e.g., build it via RuleBuilder in these tests) to reduce duplication, but it’s not required for this PR.

commit_check/rule_builder.py (1)

227-231: _get_allowed_branch_names behavior and DEFAULT_BRANCH_NAMES usage

_get_allowed_branch_names mirrors the commit/branch type helpers and behaves reasonably:

  • Uses branch_config.get("allow_branch_names", DEFAULT_BRANCH_NAMES) and
  • Deduplicates while preserving order via dict.fromkeys.

Two optional improvements you might consider:

  • If DEFAULT_BRANCH_NAMES is intended to ever hold non-empty defaults, centralizing the base names there (instead of in _build_conventional_branch_regex) would avoid duplication with docs.
  • Optionally validate that allow_branch_names is a list to catch misconfigured TOML (today a string would be treated as an iterable of characters, similar to _get_allowed_branch_types).

Neither is blocking; the current behavior is internally consistent.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 996758d and 4d84083.

📒 Files selected for processing (6)
  • commit_check/__init__.py (1 hunks)
  • commit_check/rule_builder.py (3 hunks)
  • commit_check/rules_catalog.py (1 hunks)
  • docs/configuration.rst (2 hunks)
  • tests/engine_test.py (1 hunks)
  • tests/rule_builder_test.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
docs/**

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Maintain Sphinx documentation under docs/ to build HTML docs with sphinx-build

Files:

  • docs/configuration.rst
tests/**

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Ensure tests run via pytest -v and cover commit, branch, author, and CLI behaviors

Files:

  • tests/rule_builder_test.py
  • tests/engine_test.py
🧠 Learnings (9)
📓 Common learnings
Learnt from: CR
Repo: commit-check/commit-check PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-03T10:28:06.793Z
Learning: Applies to commit_check/branch.py : Allow special branches: master, main, HEAD, PR-*
Learnt from: CR
Repo: commit-check/commit-check PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-03T10:28:06.793Z
Learning: Applies to commit_check/branch.py : Enforce Conventional Branch prefixes: bugfix/, feature/, release/, hotfix/, task/, chore/
Learnt from: CR
Repo: commit-check/commit-check PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-03T10:28:06.793Z
Learning: Applies to commit_check/commit.py : Support breaking change notation with ! (e.g., feat!: breaking change)
Learnt from: CR
Repo: commit-check/commit-check PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-03T10:28:06.793Z
Learning: Applies to commit_check/commit.py : Support the set of commit types: build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test
Learnt from: CR
Repo: commit-check/commit-check PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-03T10:28:06.793Z
Learning: Applies to commit_check/commit.py : Support optional scope in commits, e.g., feat(api): add endpoint
📚 Learning: 2025-10-03T10:28:06.793Z
Learnt from: CR
Repo: commit-check/commit-check PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-03T10:28:06.793Z
Learning: Applies to commit_check/branch.py : Enforce Conventional Branch prefixes: bugfix/, feature/, release/, hotfix/, task/, chore/

Applied to files:

  • docs/configuration.rst
  • commit_check/rules_catalog.py
  • commit_check/__init__.py
  • commit_check/rule_builder.py
📚 Learning: 2025-10-03T10:28:06.793Z
Learnt from: CR
Repo: commit-check/commit-check PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-03T10:28:06.793Z
Learning: Applies to commit_check/branch.py : Allow special branches: master, main, HEAD, PR-*

Applied to files:

  • docs/configuration.rst
  • commit_check/rules_catalog.py
  • commit_check/__init__.py
  • commit_check/rule_builder.py
📚 Learning: 2025-10-03T10:28:06.793Z
Learnt from: CR
Repo: commit-check/commit-check PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-03T10:28:06.793Z
Learning: Applies to tests/** : Ensure tests run via pytest -v and cover commit, branch, author, and CLI behaviors

Applied to files:

  • tests/rule_builder_test.py
  • tests/engine_test.py
📚 Learning: 2025-10-03T10:28:06.793Z
Learnt from: CR
Repo: commit-check/commit-check PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-03T10:28:06.793Z
Learning: Applies to .commit-check.yml : Maintain default validation rules for the tool in .commit-check.yml

Applied to files:

  • commit_check/rules_catalog.py
  • commit_check/rule_builder.py
📚 Learning: 2025-10-03T10:28:06.793Z
Learnt from: CR
Repo: commit-check/commit-check PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-03T10:28:06.793Z
Learning: Applies to commit_check/commit.py : Support breaking change notation with ! (e.g., feat!: breaking change)

Applied to files:

  • commit_check/rules_catalog.py
  • commit_check/rule_builder.py
📚 Learning: 2025-10-03T10:28:06.793Z
Learnt from: CR
Repo: commit-check/commit-check PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-03T10:28:06.793Z
Learning: Applies to commit_check/main.py : Expose CLI flags: --message, --branch, --help, --version, --config, --dry-run; support combining checks

Applied to files:

  • commit_check/rules_catalog.py
  • commit_check/__init__.py
  • commit_check/rule_builder.py
📚 Learning: 2025-10-03T10:28:06.793Z
Learnt from: CR
Repo: commit-check/commit-check PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-03T10:28:06.793Z
Learning: Applies to commit_check/commit.py : Support the set of commit types: build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test

Applied to files:

  • commit_check/rule_builder.py
📚 Learning: 2025-10-03T10:28:06.793Z
Learnt from: CR
Repo: commit-check/commit-check PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-03T10:28:06.793Z
Learning: Applies to commit_check/commit.py : Enforce Conventional Commits format: type(scope): description

Applied to files:

  • commit_check/rule_builder.py
🧬 Code graph analysis (1)
tests/rule_builder_test.py (2)
commit_check/rule_builder.py (2)
  • _build_conventional_branch_rule (121-138)
  • _get_allowed_branch_names (227-230)
commit_check/rules_catalog.py (1)
  • RuleCatalogEntry (8-12)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: install (3.14, windows-latest)
  • GitHub Check: install (3.10, windows-latest)
  • GitHub Check: install (3.9, windows-latest)
  • GitHub Check: install (3.12, ubuntu-24.04)
  • GitHub Check: install (3.10, macos-latest)
  • GitHub Check: install (3.14, ubuntu-24.04)
  • GitHub Check: install (3.11, windows-latest)
  • GitHub Check: install (3.13, macos-latest)
  • GitHub Check: install (3.13, windows-latest)
  • GitHub Check: install (3.9, macos-latest)
  • GitHub Check: install (3.11, macos-latest)
  • GitHub Check: install (3.10, ubuntu-24.04)
  • GitHub Check: install (3.13, ubuntu-24.04)
  • GitHub Check: install (3.12, windows-latest)
  • GitHub Check: install (3.12, macos-latest)
  • GitHub Check: install (3.11, ubuntu-24.04)
  • GitHub Check: install (3.9, ubuntu-24.04)
  • GitHub Check: Run benchmarks
🔇 Additional comments (3)
docs/configuration.rst (1)

48-48: allow_branch_names documentation is clear and matches implementation

The example config and options table for allow_branch_names correctly describe:

  • It as a list[str] of additional standalone branch names, and
  • That master, main, HEAD, and PR-* are always allowed by default.

This aligns with the base names used in RuleBuilder._build_conventional_branch_regex, so the docs and behavior are in sync.

Also applies to: 144-148

tests/rule_builder_test.py (1)

159-228: RuleBuilder tests thoroughly cover allow_branch_names behavior

The new tests exercise the key scenarios:

  • Default (no allow_branch_names key) uses only base names.
  • Custom list merges base and custom names into the regex.
  • Explicit empty list still keeps base names.
  • Duplicates are removed while preserving order via _get_allowed_branch_names.

This gives good confidence in the new branch-name handling logic.

commit_check/rule_builder.py (1)

128-131: Branch regex construction correctly incorporates additional allowed names

The updated _build_conventional_branch_rule + _build_conventional_branch_regex now:

  • Use allowed_types for <type>/... branches, and
  • Combine hard-coded base names (master, main, HEAD, PR-.+) with configured allowed_names.

This matches the documented behavior (base names always allowed; extra names via allow_branch_names). The resulting pattern:

types_pattern = "|".join(allowed_types)
base_names = ["master", "main", "HEAD", "PR-.+"]
all_names = base_names + allowed_names
names_pattern = ")|(".join(all_names)
regex = rf"^({types_pattern})\/.+|({names_pattern})"

is consistent with the previous hard-coded regex while making the extra names configurable.

Also applies to: 237-246

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for configuring additional allowed branch names through a new allow_branch_names configuration option. This enhancement allows users to specify standalone branch names (like "develop" or "staging") that should be accepted alongside the conventional branch type/description format.

Key changes:

  • Added allow_branch_names configuration option with empty list as default
  • Modified branch validation regex to include both default and custom branch names
  • Updated documentation to describe the new configuration option

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
commit_check/init.py Adds DEFAULT_BRANCH_NAMES constant as empty list
commit_check/rule_builder.py Implements _get_allowed_branch_names method and updates regex builder to include custom branch names
commit_check/rules_catalog.py Updates suggestion message to mention allow_branch_names option
docs/configuration.rst Documents the new allow_branch_names configuration option
tests/rule_builder_test.py Adds comprehensive tests for default, custom, empty, and duplicate branch name scenarios
tests/engine_test.py Adds integration tests validating branch names are properly allowed or rejected

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 15, 2025

CodSpeed Performance Report

Merging #336 will degrade performances by 39.93%

Comparing fix/issue-335 (4d84083) with main (c792143)1

Summary

❌ 1 regression
✅ 159 untouched
🆕 7 new
⏩ 85 skipped2

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
test_main_with_message_empty_string_no_stdin_with_git 4.7 ms 7.7 ms -39.93%
🆕 test_rule_builder_allow_branch_names_empty_list N/A 141.9 µs N/A
🆕 test_rule_builder_allow_branch_names_with_duplicates N/A 113.5 µs N/A
🆕 test_rule_builder_allow_branch_names_default N/A 141.8 µs N/A
🆕 test_branch_validator_develop_branch_not_allowed N/A 1.3 ms N/A
🆕 test_branch_validator_develop_branch_allowed N/A 1.2 ms N/A
🆕 test_rule_builder_allow_branch_names_custom N/A 144.4 µs N/A
🆕 test_branch_validator_staging_branch_allowed N/A 1.2 ms N/A

Footnotes

  1. No successful run was found on main (996758d) during the generation of this report, so c792143 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 85 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@shenxianpeng shenxianpeng merged commit 22cf07a into main Dec 15, 2025
35 of 36 checks passed
@shenxianpeng shenxianpeng deleted the fix/issue-335 branch December 15, 2025 19:31
@shenxianpeng shenxianpeng added enhancement New feature or request and removed documentation Improvements or additions to documentation labels Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request minor A minor version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allowing the develop branch

2 participants