Skip to content

Comments

refactor: change parse_cli_args to use data-driven approach#358

Merged
shenxianpeng merged 2 commits intofeature/enhance-configrationfrom
copilot/sub-pr-357
Feb 1, 2026
Merged

refactor: change parse_cli_args to use data-driven approach#358
shenxianpeng merged 2 commits intofeature/enhance-configrationfrom
copilot/sub-pr-357

Conversation

Copy link
Contributor

Copilot AI commented Feb 1, 2026

The parse_cli_args method contained ~75 lines of repetitive if statements checking individual CLI arguments, making it difficult to maintain and error-prone when adding new configuration options.

Changes

  • Added CLI_ARG_MAPPING dictionary - Maps CLI argument names to their (section, key) config pairs, following the same pattern as ENV_VAR_MAPPING
  • Refactored parse_cli_args to use iteration - Replaced individual if statements with a single loop over the mapping, reducing method from ~75 lines to ~14 lines

Before

if hasattr(args, "conventional_commits") and args.conventional_commits is not None:
    config["commit"]["conventional_commits"] = args.conventional_commits
if hasattr(args, "subject_capitalized") and args.subject_capitalized is not None:
    config["commit"]["subject_capitalized"] = args.subject_capitalized
# ... 15+ more identical patterns

After

CLI_ARG_MAPPING = {
    "conventional_commits": ("commit", "conventional_commits"),
    "subject_capitalized": ("commit", "subject_capitalized"),
    # ...
}

for arg_name, (section, key) in ConfigMerger.CLI_ARG_MAPPING.items():
    if hasattr(args, arg_name):
        value = getattr(args, arg_name)
        if value is not None:
            config[section][key] = value

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 1, 2026

Copilot AI changed the title [WIP] Address feedback on configuration enhancements for CLI and TOML support Refactor parse_cli_args to use data-driven approach Feb 1, 2026
Copilot AI requested a review from shenxianpeng February 1, 2026 19:17
@shenxianpeng shenxianpeng changed the title Refactor parse_cli_args to use data-driven approach refactor: change parse_cli_args to use data-driven approach Feb 1, 2026
@shenxianpeng shenxianpeng marked this pull request as ready for review February 1, 2026 19:19
@shenxianpeng shenxianpeng requested a review from a team as a code owner February 1, 2026 19:19
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 1, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Feb 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.35%. Comparing base (8f80ac6) to head (13ee6ff).
⚠️ Report is 1 commits behind head on feature/enhance-configration.

Additional details and impacted files
@@                       Coverage Diff                        @@
##           feature/enhance-configration     #358      +/-   ##
================================================================
+ Coverage                         93.12%   94.35%   +1.22%     
================================================================
  Files                                 9        9              
  Lines                               829      797      -32     
================================================================
- Hits                                772      752      -20     
+ Misses                               57       45      -12     

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

@shenxianpeng shenxianpeng merged commit 1d8f9a2 into feature/enhance-configration Feb 1, 2026
27 checks passed
@shenxianpeng shenxianpeng deleted the copilot/sub-pr-357 branch February 1, 2026 19:21
shenxianpeng added a commit that referenced this pull request Feb 1, 2026
* feat: Enhance configuration management with CLI, env vars, and TOML support

- Introduced a new ConfigMerger class to handle merging configurations from multiple sources: command-line arguments, environment variables, TOML files, and defaults.
- Added command-line options for various commit and branch configurations, including subject length, imperative mood, and allowed commit types.
- Updated README and configuration documentation to reflect new configuration methods and examples.
- Implemented comprehensive tests for CLI argument integration, environment variable handling, and configuration priority.
- Ensured backward compatibility with existing configuration files while providing enhanced flexibility for users.

* chore: Update docs/configuration.rst

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: Update commit-check version to v2.3.0 in README

* refactor: change parse_cli_args to use data-driven approach (#358)

* Initial plan

* refactor: Use data-driven approach in parse_cli_args to reduce duplication

Co-authored-by: shenxianpeng <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: shenxianpeng <[email protected]>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: shenxianpeng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants