Skip to content

fix(message): protect the message regex check #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2025

Conversation

StaticRocket
Copy link
Contributor

@StaticRocket StaticRocket commented Jul 14, 2025

Protect the "regex" key check by first verifying that the check type is "message". Previously check_commit_msg was verifying that all check configuration structures had valid regex keys. This is unnecessary and does not follow the pattern of other checks.

Summary by CodeRabbit

  • Refactor
    • Improved handling of empty regex checks to apply only to relevant check types, ensuring more precise validation behavior.

Protect the "regex" key check by first verifying that the check type is
"message". Previously check_commit_msg was verifying that all check
configuration structures had valid regex keys. This is unnecessary and
does not follow the pattern of other checks.

Signed-off-by: Randolph Sapp <rs@ti.com>
@StaticRocket StaticRocket requested a review from a team as a code owner July 14, 2025 20:04
@StaticRocket StaticRocket requested review from shenxianpeng and removed request for a team July 14, 2025 20:04
Copy link
Contributor

coderabbitai bot commented Jul 14, 2025

Walkthrough

The change refactors the logic for handling empty regex strings in commit checks. The empty regex check and early return are now performed only when the check type is 'message', rather than for all check types. The rest of the control flow and error handling remain unchanged.

Changes

File(s) Change Summary
commit_check/commit.py Moved the empty regex check inside the 'message' check type branch, limiting its scope.

Poem

In the warren of code, a check was set free,
Now regexes are checked with more specificity.
Only messages get the empty string glance,
Other types continue their regex dance.
With logic refined and scope made tight,
This rabbit hops on—code flowing just right! 🐇✨

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

Copy link

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

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

42-46: LGTM! Consider adding defensive checks for robustness.

The change correctly moves the empty regex validation inside the message check conditional block, which aligns with the PR objective and maintains consistency with other check types like check_commit_signoff.

Consider making the regex validation more robust by handling edge cases:

        if check['check'] == 'message':
-            if check['regex'] == "":
+            if not check.get('regex') or check['regex'].strip() == "":
                print(
                    f"{YELLOW}Not found regex for commit message. skip checking.{RESET_COLOR}",
                )
                return PASS

This improvement would:

  • Handle cases where the 'regex' key might not exist using get()
  • Check for None values and whitespace-only strings
  • Maintain backward compatibility with existing behavior
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 952b91f and 156a1cd.

📒 Files selected for processing (1)
  • commit_check/commit.py (1 hunks)

Copy link

codecov bot commented Jul 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.13%. Comparing base (952b91f) to head (156a1cd).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #260   +/-   ##
=======================================
  Coverage   99.13%   99.13%           
=======================================
  Files           8        8           
  Lines         347      347           
=======================================
  Hits          344      344           
  Misses          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.

Copy link

codspeed-hq bot commented Jul 14, 2025

CodSpeed Performance Report

Merging #260 will not alter performance

Comparing StaticRocket:bugfix/message-check (156a1cd) with main (2b9711c)

Summary

✅ 104 untouched benchmarks

@StaticRocket
Copy link
Contributor Author

This broke with the addition of 2b9711c

@shenxianpeng shenxianpeng merged commit 2491296 into commit-check:main Jul 14, 2025
57 of 60 checks passed
@shenxianpeng shenxianpeng added the bug Something isn't working label Jul 14, 2025
@shenxianpeng
Copy link
Contributor

@StaticRocket Thank you so much for the patch! I've released a new version, v0.9.1 commit-check/commit-check-action. Hopefully, it will resolve the failure in your workflow.

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.

2 participants