8000 fix: allow accented letters in author name by kohanyirobert · Pull Request #221 · commit-check/commit-check · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: allow accented letters in author name #221

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

Conversation

kohanyirobert
Copy link
Contributor
@kohanyirobert kohanyirobert commented Feb 22, 2025

Allow accented letters (e.g. áéó, etc.) in an author's name. I think this is quite commonplace (e.g. my name contains accented letters).

Since Python doesn't allow Unicode character class matching this needs to be added to the existing regex:

[À-ÖØ-öø-ÿĀ-ž\u0100-\u017F\u0180-\u024F]

This matches the following ranges:
À-Ö → Matches uppercase Latin letters with diacritics from À (U+00C0) to Ö (U+00D6).
Ø-ö → Matches uppercase Ø (U+00D8) to lowercase ö (U+00F6).
ø-ÿ → Matches lowercase ø (U+00F8) to ÿ (U+00FF).
Ā-ž → Matches Latin Extended-A characters from Ā (U+0100) to ž (U+017F).
\u0100-\u017F → Explicitly specifies the same range as Ā-ž in Unicode notation.
\u0180-\u024F → Matches Latin Extended-B characters, covering additional accented and special Latin characters.

This covers quite a lot I think. Also, I don't there is an argument over not having something like the default, hence the PR, or is there?

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced commit validation to support a wider range of author name characters, including accented and international letters.
  • Tests
    • Added tests to verify that commit validation handles author names with accented characters correctly.

Allow accented letters (e.g. áéó, etc.) in an
author's name.
Copy link
Contributor
coderabbitai bot commented Feb 22, 2025

Walkthrough

The changes update the commit check to support an extended range of Unicode characters in author names by refining its regular expression. Additionally, the test suite now includes a new test that verifies the behavior of the author name validation when accented characters are present. No public API declarations were modified.

Changes

File(s) Summary of Changes
commit_check/init.py Updated regex to include extended Unicode ranges (e.g., À-Ö, Ø-ö, ø-ÿ, Ā-ž, and Unicode blocks \u0100-\u017F, \u0180-\u024F) for author name validation while retaining the “[bot]” match.
.commit-check.yml Updated regex to allow broader Unicode characters in author name validation, similar to the change in __init__.py.
tests/author_test.py Added test_check_author_with_accented_letters method and a new variable fake_accented_author_value_an to verify that author names containing accented characters are correctly validated.

Possibly related PRs

  • feat: allow emojis (gitmoji) in messages #222: The changes in the main PR, which update the regex for validating author names to include more Unicode characters, are related to the changes in the retrieved PR that modify the regex for commit messages to allow emojis and a broader range of characters, as both involve regex modifications in the same file for character validation.

Suggested reviewers

  • shenxianpeng

Poem

In my burrow of code, I happily hop,
Watching accents and letters joyfully pop.
Regex now dances with diverse Unicode flair,
And test cases sing, precise and fair.
Here's to refined checks — a hoppy new tune!
🐰✨


📜 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 3440857 and 788e8d1.

📒 Files selected for processing (1)
  • commit_check/__init__.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • commit_check/init.py

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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
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 (2)
commit_check/__init__.py (1)

35-35: LGTM! Comprehensive Unicode support added for author names.

The updated regex pattern effectively supports accented letters while maintaining backward compatibility with ASCII characters and the [bot] suffix.

Consider simplifying the Unicode ranges.

The pattern includes some overlapping ranges that could be simplified:

  • Ā-ž overlaps with \u0100-\u017F
  • Consider using only the explicit Unicode ranges for better readability
-            'regex': r'^[A-Za-zÀ-ÖØ-öø-ÿĀ-ž\u0100-\u017F\u0180-\u024F ,.\'-]+$|.*(\[bot])',
+            'regex': r'^[A-Za-zÀ-ÖØ-öø-ÿ\u0100-\u017F\u0180-\u024F ,.\'-]+$|.*(\[bot])',
tests/author_test.py (1)

33-51: Add negative test cases for accented characters.

While the positive test case is good, consider adding tests for invalid scenarios:

  1. Mixed valid/invalid Unicode characters
  2. Characters outside the supported ranges
def test_check_author_with_invalid_unicode(self, mocker):
    # Test with characters outside the supported ranges
    checks = [{
        "check": "author_name",
        "regex": r'^[A-Za-zÀ-ÖØ-öø-ÿ\u0100-\u017F\u0180-\u024F ,.\'-]+$|.*(\[bot])'
    }]
    m_get_commit_info = mocker.patch(
        f"{LOCATION}.get_commit_info",
        return_value="invalid_name_🚀"  # Emoji outside supported range
    )
    m_re_match = mocker.patch(
        "re.match",
        side_effect=lambda *args: None  # Simulate no match
    )
    retval = check_author(checks, "author_name")
    assert retval == FAIL
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 41e0244 and 5c5f31b.

📒 Files selected for processing (2)
  • commit_check/__init__.py (1 hunks)
  • tests/author_test.py (2 hunks)
🔇 Additional comments (1)
tests/author_test.py (1)

12-12: LGTM! Good test data with accented characters.

The test variable includes a good mix of accented characters and follows the existing naming convention.

@kohanyirobert
Copy link
Contributor Author

The check failed due to my name not passing the check ... :)

Commit rejected.                                                  
                                                                  
Type author_name check failed => Kohányi Róbert 

@shenxianpeng
Copy link
Contributor

Hi @kohanyirobert,

Thanks again for your pull request! the default regex only covers the general scenario.

But you can add your own .commit-check.yml file to customize your configuration to cover more scenarios https://github.com/commit-check/commit-check?tab=readme-ov-file#use-custom-configuration

Please let me know if you have any questions or suggestions.

@shenxianpeng
Copy link
Contributor
shenxianpeng commented Feb 23, 2025

Allow accented letters (e.g. áéó, etc.) in an author's name. I think this is quite commonplace (e.g. my name contains accented letters).

Agree.

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

🧹 Nitpick comments (2)
commit_check/__init__.py (1)

35-35: Simplify the regex pattern by removing overlapping ranges.

The pattern includes overlapping ranges that could be simplified:

  • Ā-ž overlaps with \u0100-\u017F

Apply this diff to simplify the pattern while maintaining the same functionality:

-            'regex': r'^[A-Za-zÀ-ÖØ-öø-ÿĀ-ž\u0100-\u017F\u0180-\u024F ,.\'-]+$|.*(\[bot])',
+            'regex': r'^[A-Za-zÀ-ÖØ-öø-ÿ\u0100-\u017F\u0180-\u024F ,.\'-]+$|.*(\[bot])',
.commit-check.yml (1)

17-17: Simplify the regex pattern to match commit_check/init.py.

The pattern correctly allows accented characters in author names, which meets the PR objective. However, for consistency with the suggested changes in commit_check/__init__.py, consider simplifying the overlapping ranges.

Apply this diff to simplify the pattern:

-    regex: ^[A-Za-zÀ-ÖØ-öø-ÿĀ-ž\u0100-\u017F\u0180-\u024F ,.\'-]+$|.*(\[bot])
+    regex: ^[A-Za-zÀ-ÖØ-öø-ÿ\u0100-\u017F\u0180-\u024F ,.\'-]+$|.*(\[bot])
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5c5f31b and 3440857.

📒 Files selected for processing (2)
  • .commit-check.yml (1 hunks)
  • commit_check/__init__.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
commit_check/__init__.py

36-36: Dictionary key literal 'regex' repeated

(F601)

Copy link

@codecov-commenter
Copy link
codecov-commenter commented Feb 23, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (41e0244) to head (788e8d1).
Report is 1 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #221   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines          290       290           
=========================================
  Hits           290       290           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@shenxianpeng shenxianpeng merged commit a237cda into commit-check:main Feb 23, 2025
24 of 25 checks passed
@shenxianpeng shenxianpeng added the bug Something isn't working label Feb 23, 2025
@kohanyirobert kohanyirobert deleted the fix/broken-regex-accents branch February 23, 2025 17:17
shenxianpeng added a commit to commit-check/commit-check-action that referenced this pull request Feb 24, 2025
shenxianpeng added a commit to commit-check/commit-check-action that referenced this pull request Feb 24, 2025
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.

3 participants
0