Skip to content

fix: prefer git config user.name for author validation in BaseValidator - #461

Merged
shenxianpeng merged 3 commits into
mainfrom
bugfix/check-ai-commit-messaage
Jul 12, 2026
Merged

fix: prefer git config user.name for author validation in BaseValidator#461
shenxianpeng merged 3 commits into
mainfrom
bugfix/check-ai-commit-messaage

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Jul 6, 2026

Copy link
Copy Markdown
Member

I have an issue when I am running the following command

echo "fix: resolve race condition
Co-authored-by: Claude <noreply@anthropic.com>" | commit-check -m --ai-attribution=forbid

It looks like my latest commit from the main branch is a bot commit which user has been ignored by the cchk.toml config file

commit d10f1f956edca65696d437c37de89e59a4014d4a (origin/main, origin/HEAD, main)
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Mon Jul 6 21:05:35 2026 +0300

    ci: pre-commit autoupdate (#460)
    
    updates:
    - [github.com/astral-sh/ruff-pre-commit: v0.15.19 → v0.15.20](https://github.com/astral-sh/ruff-pre-commit/compare/v0.15.19...v0.15.20)
    - [github.com/commit-check/commit-check: v2.9.0 → v2.11.0](https://github.com/commit-check/commit-check/compare/v2.9.0...v2.11.0)
    
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

Summary by CodeRabbit

  • Bug Fixes
    • Improved ignored-author handling for branch and commit validation.
    • Prospective commits now use the configured Git author, while existing commits use their recorded author.
    • Added fallback behavior when commit author information is unavailable.
    • Branch checks now apply ignored-author rules only when configured.

@shenxianpeng
shenxianpeng requested a review from a team as a code owner July 6, 2026 21:18
@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for commit-check ready!

Name Link
🔨 Latest commit 1f3ec2a
🔍 Latest deploy log https://app.netlify.com/projects/commit-check/deploys/6a53e7cb0251cf0008c904bd
😎 Deploy Preview https://deploy-preview-461--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: 54 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

Run ID: 23392f7b-d6f3-4ab2-9666-3851748c7cf9

📥 Commits

Reviewing files that changed from the base of the PR and between 397a374 and 1f3ec2a.

📒 Files selected for processing (2)
  • commit_check/engine.py
  • tests/engine_test.py
📝 Walkthrough

Walkthrough

BaseValidator now selects the current author from Git configuration for prospective commits and commit metadata for existing commits. Branch and commit ignore-author checks use this resolver, with regression tests covering multiple validators and fallback behavior.

Changes

Author resolution and validator integration

Layer / File(s) Summary
Mode-aware author resolution
commit_check/engine.py
Adds context-sensitive author resolution and applies it to commit and branch ignore-author checks, while guarding branch checks on configured ignore authors.
Validator regression coverage
tests/engine_test.py
Adds and updates tests for branch, author, commit-message, and AI-attribution validators, including Git configuration and commit-author fallbacks.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: minor

🚥 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: using git config user.name for author validation in BaseValidator.
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
  • Commit unit tests in branch bugfix/check-ai-commit-messaage

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.

@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.24%. Comparing base (6e0ec42) to head (1f3ec2a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #461      +/-   ##
==========================================
+ Coverage   97.23%   97.24%   +0.01%     
==========================================
  Files          12       12              
  Lines        1157     1163       +6     
==========================================
+ Hits         1125     1131       +6     
  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.

@codspeed-hq

codspeed-hq Bot commented Jul 6, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 21 improved benchmarks
❌ 39 regressed benchmarks
✅ 297 untouched benchmarks
🆕 5 new benchmarks
⏩ 114 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
test_co_author_in_ignore_list_skips_validation 573.6 µs 920 µs -37.65%
test_skip_when_author_ignored 557 µs 878.5 µs -36.6%
test_default_signoff_skips_ignored_author 682.9 µs 1,023.5 µs -33.28%
test_author_validator_ignored_author 576.5 µs 857.8 µs -32.8%
test_co_author_in_ignore_list_from_commit_file 728 µs 1,043.5 µs -30.24%
test_positional_arg_nonexistent_file 3.8 ms 5.2 ms -28.32%
test_positional_arg_invalid_commit 3.8 ms 5.3 ms -27.83%
test_cli_allow_merge_commits_false 4.8 ms 6.5 ms -26.56%
test_branch_validator_ignored_author 855.9 µs 1,146 µs -25.31%
test_json_format_exit_code_matches_status 8.5 ms 11.4 ms -25.24%
test_main_with_message_file_argument 4.5 ms 5.9 ms -24.34%
test_compact_no_suggestions 4.7 ms 6.2 ms -24.27%
test_no_banner_still_shows_error_details 4.7 ms 6.2 ms -24.25%
test_compact_shows_one_line_per_failure 4.7 ms 6.2 ms -24.22%
test_positional_arg_without_message_flag 4.4 ms 5.8 ms -24.15%
test_positional_arg_with_message_flag 4.5 ms 5.9 ms -24.15%
test_env_allow_commit_types 4.8 ms 6.3 ms -24.03%
test_cli_allow_commit_types 4.7 ms 6.2 ms -24.03%
test_message_validation_with_invalid_commit 4.7 ms 6.2 ms -24.01%
test_compact_suppresses_ascii_art 4.7 ms 6.2 ms -23.97%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing bugfix/check-ai-commit-messaage (1f3ec2a) with main (6e0ec42)

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.

@github-actions github-actions Bot added bug Something isn't working tests Add test related changes labels Jul 12, 2026
…sion

The original fix replaced get_commit_info("an") unconditionally with
get_git_config_value("user.name") or get_commit_info("an") in both
_author_in_ignore_list and _should_skip_branch_validation. This fixed
the reported bug (piped stdin silently skipped when HEAD is a bot) but
introduced a regression: when validating an existing bot commit with no
stdin, the local git config user.name (a human) was used instead of the
commit's own author, so bots like dependabot/renovate were no longer
recognized as ignored.

Instead, add a mode-aware _resolve_current_author helper:

- Prospective message (stdin or commit_file): resolve from git config
  user.name first, falling back to the last commit's author. The last
  commit's author is unrelated to the pending commit.
- Existing commit (no stdin, no commit_file): resolve from the last
  commit's author first, falling back to git config. The commit being
  validated is the last commit.

Fixes the reported bug without breaking dependabot/renovate skip.
fix: add test for _resolve_current_author fallback path (coverage)
@shenxianpeng
shenxianpeng force-pushed the bugfix/check-ai-commit-messaage branch from 397a374 to 1f3ec2a Compare July 12, 2026 19:15
@sonarqubecloud

Copy link
Copy Markdown

@shenxianpeng shenxianpeng removed the tests Add test related changes label Jul 12, 2026

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

🧹 Nitpick comments (1)
tests/engine_test.py (1)

383-438: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse the existing GIT_CONFIG_VALUE constant instead of hardcoding the patch target.

The file already defines GIT_CONFIG_VALUE for "commit_check.engine.get_git_config_value" (used at lines 442, 460, 550), but these new tests (and similarly at lines 248, 489, 1295-1397, 1852-1855) hardcode the raw string repeatedly instead. SonarCloud also flags related literal duplication in this hunk (dependabot[bot], Alice Developer, pre-commit-ci[bot], get_commit_info, get_branch_name, has_commits). Consider using the established constant/fixtures for consistency.

♻️ Example fix
-            patch(
-                "commit_check.engine.get_git_config_value",
-                return_value="Alice Developer",
-            ),
+            patch(GIT_CONFIG_VALUE, return_value="Alice Developer"),
🤖 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 `@tests/engine_test.py` around lines 383 - 438, Replace hardcoded patch targets
in the affected tests with the existing GIT_CONFIG_VALUE constant, including
both BranchValidator tests and the similarly flagged occurrences in this test
module. Reuse established constants or fixtures for repeated author values and
Git helper patch targets such as get_commit_info, get_branch_name, and
has_commits where available, without changing test behavior.

Source: Linters/SAST tools

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

Nitpick comments:
In `@tests/engine_test.py`:
- Around line 383-438: Replace hardcoded patch targets in the affected tests
with the existing GIT_CONFIG_VALUE constant, including both BranchValidator
tests and the similarly flagged occurrences in this test module. Reuse
established constants or fixtures for repeated author values and Git helper
patch targets such as get_commit_info, get_branch_name, and has_commits where
available, without changing test behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f07abb15-fa41-4180-b123-a2578ad2748e

📥 Commits

Reviewing files that changed from the base of the PR and between d10f1f9 and 397a374.

📒 Files selected for processing (2)
  • commit_check/engine.py
  • tests/engine_test.py

@shenxianpeng
shenxianpeng merged commit 15c524c into main Jul 12, 2026
33 of 34 checks passed
@shenxianpeng
shenxianpeng deleted the bugfix/check-ai-commit-messaage branch July 12, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant