Skip to content

feat: add imperative mode - #258

Merged
shenxianpeng merged 6 commits into
mainfrom
feature/imperative-mood
Jul 12, 2025
Merged

feat: add imperative mode#258
shenxianpeng merged 6 commits into
mainfrom
feature/imperative-mood

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Jul 12, 2025

Copy link
Copy Markdown
Member

closes #256

Summary by CodeRabbit

  • New Features
    • Introduced a commit message check to enforce the use of the imperative mood in commit messages.
    • Added a corresponding pre-commit hook and command-line option for imperative mood checking.
  • Documentation
    • Updated documentation to describe the new imperative mood check and provide usage examples.
  • Tests
    • Added comprehensive tests to validate imperative mood checking functionality.

@coderabbitai

coderabbitai Bot commented Jul 12, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

A new imperative mood check for commit messages was introduced. This includes a wordlist of imperative verbs, a new check function, CLI integration, configuration updates, documentation, and comprehensive tests. The check can be enabled via CLI or pre-commit configuration, and ensures commit messages use the imperative mood in their subject lines.

Changes

File(s) Change Summary
commit_check/imperatives.py Added new file containing a set of imperative verbs.
commit_check/commit.py Added imperative mood check function and helpers.
commit_check/init.py Registered the imperative check in the default configuration.
commit_check/main.py Added CLI flag and logic to invoke imperative check.
.commit-check.yml Added imperative check configuration and error/suggestion messages.
.pre-commit-hooks.yaml Added new pre-commit hook configuration for imperative check.
.pre-commit-config.yaml Added commented-out example for imperative check hook.
README.rst Updated docs to reference imperative check and usage examples.
tests/commit_test.py Added extensive tests for imperative check and its helpers.
tests/main_test.py Updated tests to include imperative check in main function testing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant CommitCheckMain
    participant CommitCheckCommit
    participant ImperativesSet

    User->>CLI: Run commit-check --imperative -m <msg>
    CLI->>CommitCheckMain: Parse arguments
    CommitCheckMain->>CommitCheckCommit: check_imperative(checks, commit_msg_file)
    CommitCheckCommit->>ImperativesSet: Load imperative verbs
    CommitCheckCommit->>CommitCheckCommit: Analyze commit message subject
    CommitCheckCommit->>CommitCheckMain: Return PASS/FAIL
    CommitCheckMain->>CLI: Output result
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement an imperative mood check for commit messages using a wordlist (verbs in imperative) (#256)
Integrate imperative mood check into CLI, config, and pre-commit hooks (#256)
Provide documentation and tests for imperative mood check (#256)

Poem

A rabbit hops, commits in style,
With verbs imperative all the while.
“Add,” “Fix,” “Build”—not “Added” or “Fixed,”
Now our messages are perfectly mixed!
🐇✨
So let us cheer this check anew,
For clear commit logs—thank you!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 41b53a9 and c005ce1.

📒 Files selected for processing (10)
  • .commit-check.yml (1 hunks)
  • .pre-commit-config.yaml (1 hunks)
  • .pre-commit-hooks.yaml (1 hunks)
  • README.rst (2 hunks)
  • commit_check/__init__.py (1 hunks)
  • commit_check/commit.py (2 hunks)
  • commit_check/imperatives.py (1 hunks)
  • commit_check/main.py (2 hunks)
  • tests/commit_test.py (2 hunks)
  • tests/main_test.py (4 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions Bot added documentation Improvements or additions to documentation enhancement New feature or request labels Jul 12, 2025
@codecov

codecov Bot commented Jul 12, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 93.61702% with 3 lines in your changes missing coverage. Please review.

Project coverage is 99.13%. Comparing base (41b53a9) to head (c005ce1).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
commit_check/commit.py 93.02% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #258      +/-   ##
===========================================
- Coverage   100.00%   99.13%   -0.87%     
===========================================
  Files            7        8       +1     
  Lines          300      347      +47     
===========================================
+ Hits           300      344      +44     
- Misses           0        3       +3     

☔ 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

codspeed-hq Bot commented Jul 12, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #258 will degrade performances by 11.52%

Comparing feature/imperative-mood (c005ce1) with main (55b000f)

🎉 Hooray! pytest-codspeed just leveled up to 4.0.0!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

❌ 13 regressions
✅ 67 untouched benchmarks
🆕 24 new benchmarks
⁉️ 13 dropped benchmarks

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

Benchmarks breakdown

Benchmark BASE HEAD Change
🆕 test_check_imperative_different_check_type N/A 964.3 µs N/A
🆕 test_check_imperative_empty_checks N/A 959.8 µs N/A
🆕 test_check_imperative_fail_past_tense N/A 2.6 ms N/A
🆕 test_check_imperative_fail_present_continuous N/A 2.6 ms N/A
🆕 test_check_imperative_no_commits N/A 787.2 µs N/A
🆕 test_check_imperative_pass N/A 1 ms N/A
🆕 test_check_imperative_skip_merge_commit N/A 1 ms N/A
🆕 test_is_imperative_invalid_cases N/A 186.6 µs N/A
🆕 test_is_imperative_valid_cases N/A 145.3 µs N/A
🆕 test_main[argv0-1-0-0-0-0-0] N/A 5.7 ms N/A
⁉️ test_main[argv0-1-0-0-0-0] 5.1 ms N/A N/A
🆕 test_main[argv1-0-1-0-0-0-0] N/A 5.7 ms N/A
⁉️ test_main[argv1-0-1-0-0-0] 5.1 ms N/A N/A
🆕 test_main[argv10-1-1-1-0-0-0] N/A 6.3 ms N/A
⁉️ test_main[argv10-1-1-2-0-0] 5.7 ms N/A N/A
🆕 test_main[argv11-1-1-2-0-0-0] N/A 6.3 ms N/A
⁉️ test_main[argv11-1-1-2-1-1] 6.3 ms N/A N/A
⁉️ test_main[argv12-0-0-0-0-0] 4.4 ms N/A N/A
🆕 test_main[argv12-1-1-2-1-1-0] N/A 6.9 ms N/A
🆕 test_main[argv13-1-0-0-0-0-1] N/A 6 ms N/A
... ... ... ... ...

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

@sonarqubecloud

Copy link
Copy Markdown

@shenxianpeng
shenxianpeng marked this pull request as ready for review July 12, 2025 21:26
@shenxianpeng
shenxianpeng requested a review from a team as a code owner July 12, 2025 21:26
@shenxianpeng
shenxianpeng merged commit 2b9711c into main Jul 12, 2025
25 of 28 checks passed
@shenxianpeng
shenxianpeng deleted the feature/imperative-mood branch July 12, 2025 21:27
@shenxianpeng shenxianpeng added minor A minor version bump and removed documentation Improvements or additions to documentation labels Jul 12, 2025
@shenxianpeng shenxianpeng changed the title feat: add impreative mode feat: add imperative mode Jul 12, 2025
shenxianpeng added a commit that referenced this pull request Aug 7, 2026
* feat: report a skipped check as skipped, not as passed

A rule that never ran was reported as a pass. commit-check-action#258 is
the visible cost: every check on it rendered as a green tick and the
summary announced "All 5 checks passed", when in fact nothing had been
validated -- the author is dependabot[bot], which the org config lists in
ignore_authors. A bypassed policy was indistinguishable from an enforced
one, in the JSON, in the Python API, and in anything rendering them.

Measured on that exact case before the change: every rule came back
"status": "pass" with "value": "", the empty value being the only trace
that a skip had happened, and an incidental one at that.

Adds ValidationResult.SKIP and returns it from the guards that already
decide this -- _should_skip_commit_validation, _should_skip_branch_
validation, and the ignored-author branch of _validate_author. Those
helpers are named for skipping; they were simply reporting it as PASS.
validate_all_detailed maps SKIP to "skip" and forces the value empty,
since a rule that did not run examined nothing.

Overall status is "skip" only when every check skipped; one real verdict
still yields "pass" or "fail". Only "fail" is an error, so the exit code
is unchanged for existing callers and code branching on status == "fail"
keeps working.

The overall-status rule was duplicated between the CLI's --format json
and the Python API, which is how the CLI kept printing "pass" for a fully
skipped run after the API had been fixed. It now lives once, in
engine.overall_status(), used by both. That also fixes a latent bug in
the CLI's exit code: `0 if overall == "pass" else 1` would have turned a
skipped run into a failure.

Verified end to end in a repository shaped like #258 -- same repo, same
config, only the author differing:

    dependabot[bot]  -> overall "skip", every check "skip", exit 0
    a human          -> overall "pass", values reported,    exit 0
    a human, bad msg -> exit 1

The twelve existing tests that asserted PASS on these paths are all named
for skipping (ignored_author, skips_validation, skip_conditions); they now
assert SKIP. Four new API tests pin the behaviour, including a control
that only the author differs so the skip test cannot pass by the rules
having quietly stopped running for everyone. Reverting the skip reporting
turns the first of them red.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U9zFxq8V4qxG4aMzJhGBFn

* fix: preserve skip when the API merges checks from several runs

Review caught a third and fourth copy of the reduce-to-overall rule that
the first commit missed. validate_author(name=..., email=...) merges two
separate runs, and validate_all() merges up to three; each combined its
checks with a private `"fail" if any(...) else "pass"`, so a call in which
every nested check skipped still reported "pass" -- the exact defect the
skip status exists to prevent, surviving in the two entry points most
likely to be called by automation.

overall_status() now takes plain status strings rather than CheckOutcome
objects, which is what lets every caller share it: the CLI, _build_result,
and both combined paths, which hold already-serialised dicts. Four copies
of this rule is how it drifted in the first place, so there is now one.

Both new tests fail if the per-path rule is restored.

Also covers the two skip branches codecov flagged, in BodyValidator and in
CommitTypeValidator's non-ignore_authors path. Each comes with a control
that changes only the author, so neither can pass by the rule having
quietly stopped running for everyone. No line added by this PR is left
uncovered.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U9zFxq8V4qxG4aMzJhGBFn

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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.

Provide an imperative mood check

1 participant