Skip to content

Conversation

@shenxianpeng
Copy link
Contributor

@shenxianpeng shenxianpeng commented Oct 12, 2025

Summary by CodeRabbit

  • New Features

    • Exposed default settings for commit types, branch types, and validation rules to simplify customization.
  • Refactor

    • Centralized default settings for rule building, reducing duplication and changing how defaults are provided.
  • Documentation

    • Added a Troubleshooting guide explaining how to bypass or skip checks when needed.

@shenxianpeng shenxianpeng requested a review from a team as a code owner October 12, 2025 12:00
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 12, 2025

Walkthrough

Centralized default values were moved into module-level constants in commit_check/__init__.py and RuleBuilder was refactored to consume those constants. Class-level default attributes and on-import default rule construction were removed. Documentation added: a troubleshooting page and toctree entry.

Changes

Cohort / File(s) Summary
Centralized defaults
commit_check/__init__.py
Removed on-import default rule construction and DEFAULT_CONFIG. Added public constants: DEFAULT_COMMIT_TYPES, DEFAULT_BRANCH_TYPES, DEFAULT_BOOLEAN_RULES.
RuleBuilder refactor
commit_check/rule_builder.py
Removed RuleBuilder.DEFAULT_COMMIT_TYPES and RuleBuilder.DEFAULT_BRANCH_TYPES. Now imports and uses module-level DEFAULT_COMMIT_TYPES, DEFAULT_BRANCH_TYPES, and DEFAULT_BOOLEAN_RULES. Boolean-rule defaults resolved via DEFAULT_BOOLEAN_RULES.get(check, True). Existing ordering/deduplication logic preserved.
Documentation
docs/index.rst, docs/troubleshoot.rst
Added troubleshoot to the docs toctree and new docs/troubleshoot.rst describing bypassing checks (examples for --no-verify and SKIP env, and setting Git user).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

I twitch my whiskers, hop and write,
Constants gathered in tidy sight.
No more duplicates, rules align,
A cleaner path down rabbit line.
Cheers, carrots, and a tiny delight 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the main refactoring change by specifying that default values are being relocated to __init__.py, which directly reflects the core modifications in the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ 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 feature/move-to-init

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 the enhancement New feature or request label Oct 12, 2025
@shenxianpeng shenxianpeng added skip-changelog and removed enhancement New feature or request labels Oct 12, 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: 1

Caution

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

⚠️ Outside diff range comments (1)
commit_check/__init__.py (1)

11-11: Critical: Circular import will cause runtime failure.

The import order creates a circular dependency:

  1. Line 11 imports RuleBuilder from commit_check.rule_builder
  2. rule_builder.py (lines 6-10) imports these constants from commit_check
  3. But at that point, __init__.py is stuck at line 11 and hasn't defined the constants yet (lines 24-58)
  4. Result: ImportError: cannot import name 'DEFAULT_COMMIT_TYPES'

Move the RuleBuilder import to after the constant definitions:

 from importlib.metadata import version
-from commit_check.rule_builder import RuleBuilder
 
 # Exit codes used across the package
 PASS = 0
 FAIL = 1
 
 # ANSI color codes used for CLI output
 RED = "\033[91m"
 GREEN = "\033[92m"
 YELLOW = "\033[93m"
 RESET_COLOR = "\033[0m"
 
 # Follow conventional commits
 DEFAULT_COMMIT_TYPES = [
     "feat",
     "fix",
     "docs",
     "style",
     "refactor",
     "test",
     "chore",
     "perf",
     "build",
     "ci",
 ]
 # Follow conventional branch
 DEFAULT_BRANCH_TYPES = [
     "feature",
     "bugfix",
     "hotfix",
     "release",
     "chore",
     "feat",
     "fix",
 ]
 
 # Handle different default values for different rules
 DEFAULT_BOOLEAN_RULES = {
     "subject_capitalized": True,
     "subject_imperative": True,
     "allow_merge_commits": True,
     "allow_revert_commits": True,
     "allow_empty_commits": True,
     "allow_fixup_commits": True,
     "allow_wip_commits": True,
     "require_body": False,
     "require_signed_off_by": False,
 }
 
+from commit_check.rule_builder import RuleBuilder
+
 # Default (empty) configuration translated into internal checks structure
 _rule_builder = RuleBuilder({})

Also applies to: 24-58

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 189c9d1 and a4b1a27.

📒 Files selected for processing (2)
  • commit_check/__init__.py (1 hunks)
  • commit_check/rule_builder.py (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-03T10:28:06.793Z
Learnt from: CR
PR: commit-check/commit-check#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/__init__.py
⏰ 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). (1)
  • GitHub Check: Run benchmarks
🔇 Additional comments (4)
commit_check/rule_builder.py (4)

6-10: Good centralization of defaults, but depends on fixing circular import.

The refactoring to use module-level constants is a good approach for centralizing configuration. However, these imports will fail due to the circular import issue flagged in commit_check/__init__.py. Once that's resolved by moving the RuleBuilder import to after the constant definitions, these imports will work correctly.


192-192: LGTM!

Good refactoring to use the centralized DEFAULT_BOOLEAN_RULES dictionary instead of a local defaults dictionary.


217-217: LGTM!

Good refactoring to use the module-level DEFAULT_COMMIT_TYPES constant. Note that DEFAULT_COMMIT_TYPES is missing the 'revert' type as flagged in the commit_check/__init__.py review.


222-222: LGTM!

Good refactoring to use the module-level DEFAULT_BRANCH_TYPES constant.

@github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request labels Oct 12, 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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4b1a27 and 33597c0.

📒 Files selected for processing (4)
  • commit_check/__init__.py (1 hunks)
  • commit_check/rule_builder.py (3 hunks)
  • docs/index.rst (1 hunks)
  • docs/troubleshoot.rst (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docs/index.rst
🚧 Files skipped from review as they are similar to previous changes (2)
  • commit_check/rule_builder.py
  • commit_check/init.py
🧰 Additional context used
📓 Path-based instructions (1)
docs/**

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

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

Files:

  • docs/troubleshoot.rst

Comment on lines +24 to +45
Bypass Specific Hook
~~~~~~~~~~~~~~~~~~~~

Use the ``--no-verify`` flag to skip the pre-commit hook:

.. code-block:: shell

# Amend the commit without running hooks
git commit --amend --author="Xianpeng Shen <xianpeng.shen@gmail.com>" --no-edit --no-verify

Bypass All Hooks
----------------

Alternatively, use the ``SKIP=your-hook-name`` environment variable, like below:

.. code-block:: shell

# Set the correct Git author name
git config user.name "Xianpeng Shen"

# Force amend while skipping the specified hook
SKIP=check-author-name git commit --amend --author="Xianpeng Shen <xianpeng.shen@gmail.com>" --no-edit
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix misleading hook-bypass guidance

git commit --no-verify disables all hooks, while SKIP=… (pre-commit) skips only named hooks. The current headings/text invert that behavior and will mislead users. Please correct the descriptions/headings so they reflect the actual scope of each option.

-Bypass Specific Hook
-~~~~~~~~~~~~~~~~~~~~
-
-Use the ``--no-verify`` flag to skip the pre-commit hook:
+Bypass All Hooks
+----------------
+
+Use the ``--no-verify`` flag to skip every pre-commit and commit-msg hook:
@@
-Bypass All Hooks
-----------------
-
-Alternatively, use the ``SKIP=your-hook-name`` environment variable, like below:
+Skip Selected Hooks
+~~~~~~~~~~~~~~~~~~~
+
+Alternatively, use the ``SKIP=your-hook-name`` environment variable with pre-commit to skip only particular hooks:
🤖 Prompt for AI Agents
In docs/troubleshoot.rst around lines 24 to 45 the headings and descriptions
incorrectly state hook scopes: git commit --no-verify actually disables all
hooks while SKIP=your-hook-name only skips the named pre-commit hooks; update
the headings and explanatory text so the "Bypass All Hooks" section describes
--no-verify and its example, and the "Bypass Specific Hook" section describes
SKIP=your-hook-name and its example, adjusting the comments to state that
--no-verify disables all hooks and SKIP skips only the specified hook(s).

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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4b1a27 and 33597c0.

📒 Files selected for processing (4)
  • commit_check/__init__.py (1 hunks)
  • commit_check/rule_builder.py (3 hunks)
  • docs/index.rst (1 hunks)
  • docs/troubleshoot.rst (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • docs/index.rst
  • docs/troubleshoot.rst
🚧 Files skipped from review as they are similar to previous changes (1)
  • commit_check/init.py
🔇 Additional comments (3)
commit_check/rule_builder.py (3)

192-192: Enhanced flexibility with per-check default values.

The change from a hardcoded True to DEFAULT_BOOLEAN_RULES.get(check, True) allows different boolean checks to have different default values while maintaining backward compatibility with the True fallback.


222-222: Confirm DEFAULT_BRANCH_TYPES matches legacy defaults.

DEFAULT_BRANCH_TYPES is currently defined as ["feature", "bugfix", "hotfix", "release", "chore", "feat", "fix"]. Ensure this exactly reflects the previous hardcoded branch-type list to maintain backward compatibility.


6-10: Ensure default constants preserve previous behavior.

Confirm that DEFAULT_COMMIT_TYPES, DEFAULT_BRANCH_TYPES, and DEFAULT_BOOLEAN_RULES in commit_check/__init__.py exactly match the hardcoded defaults you removed from rule_builder.py to avoid unintended behavior changes.

@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Oct 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.98%. Comparing base (189c9d1) to head (2135166).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #299      +/-   ##
==========================================
- Coverage   87.33%   86.98%   -0.35%     
==========================================
  Files           8        8              
  Lines         687      684       -3     
==========================================
- Hits          600      595       -5     
- Misses         87       89       +2     

☔ 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.

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 12, 2025

CodSpeed Performance Report

Merging #299 will not alter performance

Comparing feature/move-to-init (2135166) with main (1e4db5d)1

Summary

✅ 27 untouched
⏩ 85 skipped2

Footnotes

  1. No successful run was found on main (189c9d1) during the generation of this report, so 1e4db5d 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 removed documentation Improvements or additions to documentation enhancement New feature or request labels Oct 12, 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)
commit_check/__init__.py (1)

1-7: Update module docstring to reflect new exports.

The docstring lists exports but doesn't mention the newly added DEFAULT_COMMIT_TYPES, DEFAULT_BRANCH_TYPES, and DEFAULT_BOOLEAN_RULES constants.

Apply this diff to update the docstring:

 """The commit-check package's base module.
 
 Exports:
         PASS / FAIL exit codes
         ANSI color constants
+        DEFAULT_COMMIT_TYPES
+        DEFAULT_BRANCH_TYPES
+        DEFAULT_BOOLEAN_RULES
         __version__ (package version)
 """
🧹 Nitpick comments (2)
commit_check/__init__.py (2)

21-56: Consider defining __all__ for explicit exports.

The module doesn't define __all__, meaning all public symbols (those not starting with _) will be exported by from commit_check import *. Consider adding __all__ to explicitly control which symbols are exported, improving API clarity and preventing unintended exports if internal helpers are added later.

Add this after the imports (around line 10):

__all__ = [
    "PASS",
    "FAIL",
    "RED",
    "GREEN",
    "YELLOW",
    "RESET_COLOR",
    "DEFAULT_COMMIT_TYPES",
    "DEFAULT_BRANCH_TYPES",
    "DEFAULT_BOOLEAN_RULES",
    "CONFIG_FILE",
    "__version__",
]

35-43: Remove or document shorthand branch prefixes in DEFAULT_BRANCH_TYPES.
In commit_check/init.py (lines 35–43), DEFAULT_BRANCH_TYPES includes both ‘feature’/‘feat’ and ‘bugfix’/‘fix’, but all existing tests and patterns use only the long forms. If shorthand support isn’t required, remove ‘feat’ and ‘fix’.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 33597c0 and 2135166.

📒 Files selected for processing (2)
  • commit_check/__init__.py (1 hunks)
  • docs/troubleshoot.rst (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docs/troubleshoot.rst
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-03T10:28:06.793Z
Learnt from: CR
PR: commit-check/commit-check#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/__init__.py
⏰ 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). (11)
  • GitHub Check: install (3.14, macos-latest)
  • GitHub Check: install (3.9, macos-latest)
  • GitHub Check: install (3.13, windows-latest)
  • GitHub Check: install (3.14, windows-latest)
  • GitHub Check: install (3.14, ubuntu-24.04)
  • GitHub Check: install (3.10, windows-latest)
  • GitHub Check: install (3.12, windows-latest)
  • GitHub Check: install (3.11, windows-latest)
  • GitHub Check: install (3.10, macos-latest)
  • GitHub Check: install (3.9, ubuntu-24.04)
  • GitHub Check: install (3.9, windows-latest)

@shenxianpeng shenxianpeng merged commit 734686b into main Oct 12, 2025
31 of 32 checks passed
@shenxianpeng shenxianpeng deleted the feature/move-to-init branch October 12, 2025 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant