Skip to content

fix: Handle MaaS acronym in class-generator filename generation#2665

Merged
myakove merged 2 commits intomainfrom
fix/issue-2664-class-generator-incorrect-filename
Mar 5, 2026
Merged

fix: Handle MaaS acronym in class-generator filename generation#2665
myakove merged 2 commits intomainfrom
fix/issue-2664-class-generator-incorrect-filename

Conversation

@myakove
Copy link
Collaborator

@myakove myakove commented Mar 5, 2026

Fixes #2664

Changes

  • Add normalize_acronyms preprocessing in convert_camel_case_to_snake_case() to handle mixed-case acronyms like MaaS that get incorrectly split to maa_s
  • Add filename validation in class-generator that detects single-character segments (_x_) in generated filenames and logs an error directing the user to add the acronym to normalize_acronyms
  • Print target filename during --dry-run mode
  • Add test cases for MaaSModelRef, MaaSAuthPolicy, MaaSSubscription

Summary by CodeRabbit

  • Bug Fixes

    • Added runtime validation with descriptive errors for invalid acronym patterns in resource naming.
    • Improved handling of mixed-case acronyms so they convert to expected snake_case forms.
  • Chores

    • Dry-run output now consistently shows the would-be file path and rendered code with unified messaging.
  • Tests

    • Added tests covering mixed-case acronym scenarios in naming conversions.

@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3837fff6-3d9b-4c50-b1f4-26b978df003d

📥 Commits

Reviewing files that changed from the base of the PR and between ee83d44 and e95254b.

📒 Files selected for processing (1)
  • class_generator/core/generator.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • class_generator/core/generator.py

Walkthrough

Adds preprocessing to treat the "MaaS" acronym as a single word during CamelCase→snake_case conversion and adds runtime validation in the class generator to detect invalid acronym-derived patterns in formatted filenames. Three tests were added to cover MaaS filename outputs.

Changes

Cohort / File(s) Summary
Generator validation & dry-run output
class_generator/core/generator.py
Adds re-based validation to detect invalid acronym patterns (e.g., _\<lowercase\>_ segments) in formatted kinds and raises a descriptive ValueError when found. Consolidates dry-run output to use a Console instance variable for printing rendered code and file path; applies the validation in both generation entry points.
Acronym normalization in utilities
ocp_resources/utils/utils.py
Adds a preprocessing step to normalize mixed-case acronym "MaaS" to "Maas" before the existing camelCase→snake_case formatting logic so MaaSModelRef becomes maas_model_ref.
Tests for MaaS handling
tests/test_camelcase_to_snake.py
Adds three parameterized tests: MaaSModelRefmaas_model_ref, MaaSAuthPolicymaas_auth_policy, MaaSSubscriptionmaas_subscription.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provides a clear summary of changes and links to issue #2664, but does not follow the required template structure with all specified sections (Short description, More details, Why we need it, Special notes, Bug). Reformat the PR description to include all template sections: Short description, More details, What this PR does/why we need it, Which issue(s) this fixes, Special notes, and Bug section.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: Handle MaaS acronym in class-generator filename generation' accurately describes the main change—addressing the MaaS acronym handling issue in filename generation.
Linked Issues check ✅ Passed The PR successfully addresses issue #2664 by implementing acronym normalization in camelCase-to-snake_case conversion, adding validation for single-character segments, and adding test cases for MaaS-based resources.
Out of Scope Changes check ✅ Passed All changes align with the scope of issue #2664: acronym handling, filename validation, dry-run printing, and related test cases. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/issue-2664-class-generator-incorrect-filename

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 and usage tips.

@rh-bot-1
Copy link

rh-bot-1 commented Mar 5, 2026

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the OWNERS file in the repository root
  • Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are automatically applied based on changes
  • Issue Creation: Disabled for this repository
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified
  • Labels: All label categories are enabled (default configuration)

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (approvers only)
  • /hold cancel - Unblock PR merging
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status
  • /reprocess - Trigger complete PR workflow reprocessing (useful if webhook failed or configuration changed)
  • /regenerate-welcome - Regenerate this welcome message

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /automerge - Enable automatic merging when all requirements are met (maintainers and approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest python-module-install - Test Python package installation
  • /retest conventional-title - Validate commit message format
  • /retest all - Run all available tests

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. Status Checks: All required status checks must pass
  3. No Blockers: No wip, hold, has-conflicts labels and PR must be mergeable (no conflicts)
  4. Verified: PR must be marked as verified

📊 Review Process

Approvers and Reviewers

Approvers:

  • myakove
  • rnetser

Reviewers:

  • myakove
  • rnetser
Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve
  • automerge

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is automatically removed on each new commit
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

For more information, please refer to the project documentation or contact the maintainers.

Copy link

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@class_generator/core/generator.py`:
- Around line 61-68: The validation branch that currently calls sys.exit(1)
should instead raise a RuntimeError so callers and the CLI exception handler can
handle it; in the block that logs the invalid filename (around the code in
generate_resource_file_from_dict that checks re.search(r"_[a-z]_",
formatted_kind_str)), keep the LOGGER.error call but replace the sys.exit(1)
with raise RuntimeError("<same or similar descriptive message>") so the error
message is propagated as an exception (consistent with how
class_generator()/generate_resource_file_from_dict() handles other validation
failures).

In `@tests/test_camelcase_to_snake.py`:
- Around line 35-49: Update the three pytest.param expectations to match issue
`#2664`'s filename contract: for inputs "MaaSModelRef", "MaaSAuthPolicy", and
"MaaSSubscription" change the expected outputs from "maas_model_ref",
"maas_auth_policy", "maas_subscription" to "maasmodelref", "maasauthpolicy",
"maassubscription" respectively so the tests assert all-lowercase concatenated
filenames instead of snake_case with underscores.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c84e6e66-3f6f-4384-949d-f9374d02b337

📥 Commits

Reviewing files that changed from the base of the PR and between 5af218e and ee83d44.

📒 Files selected for processing (3)
  • class_generator/core/generator.py
  • ocp_resources/utils/utils.py
  • tests/test_camelcase_to_snake.py

@rnetser
Copy link
Collaborator

rnetser commented Mar 5, 2026

/approve
/lgtm

@myakove
Copy link
Collaborator Author

myakove commented Mar 5, 2026

/verified
/approve

@myakove myakove enabled auto-merge (squash) March 5, 2026 09:50
@myakove myakove merged commit a1d68e6 into main Mar 5, 2026
7 checks passed
@myakove myakove deleted the fix/issue-2664-class-generator-incorrect-filename branch March 5, 2026 09:51
SB159 pushed a commit to SB159/openshift-python-wrapper that referenced this pull request Mar 5, 2026
…atQE#2665)

* fix: Handle MaaS acronym in class-generator filename generation

Fixes RedHatQE#2664

* fix: Replace sys.exit with raise ValueError for filename validation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

class-generator creates incorrect filename for MaaSModelRef resource

5 participants