Skip to content

feat: make author name and email check patterns configurable - #459

Merged
shenxianpeng merged 8 commits into
commit-check:mainfrom
zerwes:feature/author_checks_configurable_pattern
Jul 24, 2026
Merged

feat: make author name and email check patterns configurable#459
shenxianpeng merged 8 commits into
commit-check:mainfrom
zerwes:feature/author_checks_configurable_pattern

Conversation

@zerwes

@zerwes zerwes commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

introduces new commit config options author_name_pattern and author_email_pattern

Summary by CodeRabbit

  • New Features

    • Added configurable author email and author name pattern validation for commits.
    • Added command-line options and environment variables for customizing these patterns.
    • Author email validation now defaults to requiring an email-like format.
  • Documentation

    • Documented the new configuration options, defaults, environment variables, and CLI flags.
  • Chores

    • Added Vim swap files to the ignored files list.

@zerwes
zerwes requested a review from a team as a code owner July 6, 2026 16:55
@zerwes
zerwes requested review from shenxianpeng and removed request for a team July 6, 2026 16:55
@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for commit-check ready!

Name Link
🔨 Latest commit 0e67f51
🔍 Latest deploy log https://app.netlify.com/projects/commit-check/deploys/6a62ca64f0843a000838e8ff
😎 Deploy Preview https://deploy-preview-459--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.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@shenxianpeng, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 19 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bbfa0686-8114-424f-b73e-a6f19a070753

📥 Commits

Reviewing files that changed from the base of the PR and between 00f2a11 and 0e67f51.

📒 Files selected for processing (5)
  • README.md
  • commit_check/main.py
  • docs/configuration.rst
  • tests/config_merger_test.py
  • tests/engine_test.py
📝 Walkthrough

Walkthrough

Adds configurable commit author email and name regex patterns through defaults, environment variables, CLI options, and validation rule construction. Updates configuration documentation and ignores Vim swap files.

Changes

Author pattern validation

Layer / File(s) Summary
Author pattern configuration and CLI wiring
commit_check/config_merger.py, commit_check/main.py
Adds author pattern defaults, environment-variable mappings, CLI mappings, and parser options.
Rule builder support for author patterns
commit_check/rule_builder.py
Builds author email and name validation rules using configured patterns or catalog defaults.
Configuration documentation and repository support
docs/configuration.rst, .gitignore
Documents the new settings and adds a Vim swap-file ignore pattern.

Estimated code review effort: 3 (Moderate) | ~15–30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI as CLI parser
  participant Config as ConfigMerger
  participant Rules as RuleBuilder
  participant Validation as ValidationRule

  CLI->>Config: Provide author email/name patterns
  Config->>Rules: Merge commit author configuration
  Rules->>Rules: Select author_email or author_name check
  Rules->>Validation: Create rule with resolved regex
Loading

Suggested labels: documentation

🚥 Pre-merge checks | ✅ 5
✅ 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 matches the main change: making author name and email validation patterns configurable.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
commit_check/main.py (1)

306-318: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor: consider adding metavar for consistency.

Other str-typed options in this group (e.g., --require-rebase-target) set an explicit metavar (e.g., BRANCH). Consider metavar="REGEX" here for consistent --help output.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@commit_check/main.py` around lines 306 - 318, The `commit_group.add_argument`
definitions for `--author-email-pattern` and `--author-name-pattern` are missing
explicit `metavar` values, unlike the other string options in this group. Update
both argument declarations in `main.py` to set a consistent `metavar` such as
`REGEX` so the `--help` output matches the rest of the CLI options.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@commit_check/config_merger.py`:
- Around line 81-82: The default value for author_name_pattern is currently an
empty string, which disables name validation in the rule builder. Update the
default in the config merger to use the same catalog regex as the built-in
author-name check, and keep the existing author_email_pattern behavior unchanged
so the engine still validates author_name unless an override is explicitly
provided.

In `@commit_check/rule_builder.py`:
- Around line 245-257: The author-name rule builder is currently creating a
ValidationRule with an empty regex when the config value is unset, which makes
AuthorValidator skip the check entirely. Update _build_author_pattern_rule in
rule_builder.py to either return None when the commit config value is empty or
fall back to catalog_entry.regex so the built-in author_name_pattern remains
active. Keep the fix localized to _build_author_pattern_rule and preserve the
existing check/error/suggest fields on ValidationRule.

In `@docs/configuration.rst`:
- Around line 277-282: The configuration table entry for the CLI option is
malformed because the author-email-pattern row has an extra leading backtick,
breaking the inline literal. Update the mapping entry in the configuration table
so the ``--author-email-pattern`` value matches the same double-backtick style
as the neighboring entries, using the affected table row in
docs/configuration.rst as the target.

---

Nitpick comments:
In `@commit_check/main.py`:
- Around line 306-318: The `commit_group.add_argument` definitions for
`--author-email-pattern` and `--author-name-pattern` are missing explicit
`metavar` values, unlike the other string options in this group. Update both
argument declarations in `main.py` to set a consistent `metavar` such as `REGEX`
so the `--help` output matches the rest of the CLI options.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6dc87053-d521-4659-99d1-68b06c1610c9

📥 Commits

Reviewing files that changed from the base of the PR and between 9e26b4f and f7c685a.

📒 Files selected for processing (6)
  • .gitignore
  • README.rst
  • commit_check/config_merger.py
  • commit_check/main.py
  • commit_check/rule_builder.py
  • docs/configuration.rst

Comment thread commit_check/config_merger.py
Comment thread commit_check/rule_builder.py
Comment thread docs/configuration.rst Outdated
@shenxianpeng shenxianpeng changed the title feature: make the author check patterns configurable feat: make author name and email check patterns configurable Jul 6, 2026
Comment thread README.rst Outdated
Comment thread README.rst Outdated
Comment thread README.rst Outdated
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.28%. Comparing base (7e4e4cf) to head (0e67f51).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #459      +/-   ##
==========================================
+ Coverage   97.26%   97.28%   +0.02%     
==========================================
  Files          12       12              
  Lines        1168     1179      +11     
==========================================
+ Hits         1136     1147      +11     
  Misses         32       32              

☔ View full report in Codecov by Harness.
📢 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 force-pushed the feature/author_checks_configurable_pattern branch from 678769c to c53bc92 Compare July 6, 2026 18:20
@codspeed-hq

codspeed-hq Bot commented Jul 6, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 377 untouched benchmarks
🆕 3 new benchmarks
⏩ 114 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 test_custom_email_pattern_enforces_domain N/A 1.2 ms N/A
🆕 test_custom_name_pattern_pass_and_fail N/A 1.2 ms N/A
🆕 test_default_name_pattern_uses_builtin_regex N/A 1.2 ms N/A

Comparing zerwes:feature/author_checks_configurable_pattern (0e67f51) with main (7e4e4cf)

Open in CodSpeed

Footnotes

  1. 114 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 commented Jul 6, 2026

Copy link
Copy Markdown
Member

Hi @zerwes, thank you for your PR. Could you please explain a little for your use case why it needs to add author_name_pattern and author_email_pattern? (I'm not opposed to adding this feature, but I'd just like to hear about some use cases)

Also, could you add appropriate test cases to make sure that the newly added features work as expected?

@shenxianpeng shenxianpeng added enhancement New feature or request minor A minor version bump labels Jul 6, 2026
@zerwes

zerwes commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Hi @zerwes, thank you for your PR. Could you please explain a little for your use case why it needs to add author_name_pattern and author_email_pattern? (I'm not opposed to adding this feature, but I'd just like to hear about some use cases)

Hello @shenxianpeng
My intention is to have some restricted validation regarding author email and author name as a pre-commit check. We use pre-commit for a wide variety of tests. And as the request for the author name and email validation was made, I came around your commit-check, and realized it meets my requirements, but just was missing the configurable patterns.

Also, could you add appropriate test cases to make sure that the newly added features work as expected?

Surely. As there are some validation tests for the author name and email defined, I considered additional test as superfluous. Can you be so kind and give me a hint what kind of test you are thinking about?

Greetings from Berlin

@shenxianpeng

Copy link
Copy Markdown
Member

@zerwes Greetings from Vilnius! 👋

Could you please add the following tests? like:

  1. Tests for author_email_pattern (pass/fail cases, Config/CLI/Env support).
  2. Tests for author_name_pattern (pass/fail cases, Config/CLI/Env support).
  3. Maybe regression tests to ensure the default author-name validation still works when no custom pattern is configured.
  4. Maybe precedence tests verifying CLI/Environment Variable overrides TOML configuration.

I'd recommend letting AI generate as comprehensive a test suite as possible, or even let it review the PR and identify any missing test cases or edge cases to make sure everything is well covered.

Add tests for author_name_pattern / author_email_pattern: custom name and
email (company-domain) patterns pass/fail, env-var mapping, and a regression
guard that an empty pattern falls back to the built-in regex instead of
disabling the check.

Replace the Western-name-only example regex in the docs and README with an
email-domain example and a permissive full-name example, and correct the
author_name_pattern description (empty means built-in default, not disabled).
@shenxianpeng

Copy link
Copy Markdown
Member

I've rebased it onto main (it needed the README.rst → README.md migration resolved), added test coverage — custom name/email patterns, the env-var mapping, and a regression guard that an empty pattern falls back to the built-in regex rather than disabling the check — and swapped the example regex for a more inclusive one (the previous ^[A-Z]+...$ would reject mononyms, non-ASCII names, apostrophes, and lowercase names). Getting this merged now. Thanks for the contribution!

- Move 4 swallowed test methods back to TestAuthorValidator class
- Add metavar='REGEX' to --author-email-pattern and --author-name-pattern
- Clarify help text: --author-email/name-pattern requires the check enabled
@sonarqubecloud

Copy link
Copy Markdown

@shenxianpeng
shenxianpeng merged commit 911de5e into commit-check:main Jul 24, 2026
29 of 30 checks passed
@zerwes

zerwes commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the fixes and the merge!
Sorry, was quite busy, still had the TODOs on my backlog, but they slid down as things with higher prio dropped in.

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.

2 participants