Skip to content

Github Actions Setup assumes user has edited the toml file #62

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 2 commits into from
Mar 21, 2025

Conversation

aseembits93
Copy link
Contributor

@aseembits93 aseembits93 commented Mar 20, 2025

User description

Github Actions Setup during init assumes user has changed the other formatter to one of their choice but the init hasn't exited yet. I added an optional argument which overrides the assert check for a valid formatter.


PR Type

  • Enhancement

Description

  • Introduce override_formatter_check parameter for GitHub Actions

  • Update install_github_actions call in init function

  • Modify parse_config_file to conditionally bypass formatter check


Changes walkthrough 📝

Relevant files
Enhancement
cmd_init.py
Update GitHub Actions installation with override parameter

codeflash/cli_cmds/cmd_init.py

  • Pass override_formatter_check=True to install_github_actions
  • Update install_github_actions signature with new parameter
  • Propagate override parameter to parse_config_file call
  • +3/-3     
    config_parser.py
    Enhance config parser to bypass formatter check conditionally

    codeflash/code_utils/config_parser.py

  • Add override_formatter_check parameter to parse_config_file
  • Wrap formatter-cmds assertion in conditional check
  • Maintain existing config parsing and key conversion logic
  • +7/-5     

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • …one of their choice but the init hasn't exited yet
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Configuration Change

    The introduction of the override_formatter_check parameter in install_github_actions may affect existing workflows. Review the impact on the setup sequence and ensure that related tests cover this new branch.

    install_github_actions(override_formatter_check=True)
    Conditional Bypass

    The conditional check bypassing the formatter validation in parse_config_file requires careful verification. Confirm that this behavior is intended and does not hide configuration errors that could lead to misconfigurations.

    #see if this is happening during Github actions setup
    if not override_formatter_check:
        assert config["formatter-cmds"][0] != "your-formatter $file", (
            "The formatter command is not set correctly in pyproject.toml. Please set the "
            "formatter command in the 'formatter-cmds' key. More info - https://docs.codeflash.ai/configuration"
        )

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Conditional override flag

    Conditionally pass the override flag based on the execution environment to avoid
    bypassing validation outside GitHub Actions.

    codeflash/cli_cmds/cmd_init.py [76]

    -install_github_actions(override_formatter_check=True)
    +install_github_actions(override_formatter_check=(os.getenv("GITHUB_ACTIONS") == "true"))
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion dynamically sets the override flag based on the GITHUB_ACTIONS environment variable, which is useful for ensuring validations run appropriately; however, it introduces an external dependency (os.getenv) that must be managed, resulting in a moderate improvement.

    Medium
    Possible issue
    Explicit config validation

    Replace the assert with an explicit conditional raise to ensure the configuration is
    validated in all runtimes.

    codeflash/code_utils/config_parser.py [89-93]

    -if not override_formatter_check:
    -    assert config["formatter-cmds"][0] != "your-formatter $file", (
    -        "The formatter command is not set correctly in pyproject.toml. Please set the "
    -        "formatter command in the 'formatter-cmds' key. More info - https://docs.codeflash.ai/configuration"
    -    )
    +if not override_formatter_check and config["formatter-cmds"][0] == "your-formatter $file":
    +    raise Exception("The formatter command is not set correctly in pyproject.toml. Please set the 'formatter-cmds' key. More info - https://docs.codeflash.ai/configuration")
    Suggestion importance[1-10]: 7

    __

    Why: Replacing the assert with an explicit exception improves the reliability of error handling in production, ensuring that misconfigurations are clearly reported, although using a generic Exception may be less ideal.

    Medium

    @aseembits93 aseembits93 self-assigned this Mar 20, 2025
    @misrasaurabh1 misrasaurabh1 enabled auto-merge March 21, 2025 01:18
    @misrasaurabh1 misrasaurabh1 merged commit a74c04a into main Mar 21, 2025
    15 checks passed
    @aseembits93 aseembits93 deleted the cf-576 branch April 23, 2025 19:34
    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.

    2 participants