Skip to content

Refactore create_project_package to fix Rubocop offence#876

Open
kostyanf14 wants to merge 1 commit intoHCK-CI:masterfrom
kostyanf14:abc-size
Open

Refactore create_project_package to fix Rubocop offence#876
kostyanf14 wants to merge 1 commit intoHCK-CI:masterfrom
kostyanf14:abc-size

Conversation

@kostyanf14
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings February 23, 2026 15:47
@gemini-code-assist
Copy link

Summary of Changes

Hello @kostyanf14, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing code quality and maintainability by refactoring a key method responsible for creating project packages. The changes extract specific functionalities into dedicated methods, making the code more modular and easier to understand. This refactoring also incorporates improved logging for cases where specified file paths are invalid, contributing to more robust error handling.

Highlights

  • Code Refactoring: The create_project_package method has been refactored to improve readability and maintainability, addressing a Rubocop offense.
  • New Methods Introduced: Two new private methods, prepare_package_driver_content and prepare_package_supplemental_content, were introduced to encapsulate the logic for preparing and uploading driver and supplemental files respectively.
  • Improved Error Handling: Warning messages are now logged if a specified driver or supplemental path does not exist, preventing silent failures and providing clearer feedback.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • lib/engines/hcktest/tests.rb
    • Refactored the create_project_package method to delegate content preparation.
    • Added prepare_package_driver_content method for handling driver file uploads and path validation.
    • Added prepare_package_supplemental_content method for handling supplemental file uploads and path validation.
    • Implemented warning logs for non-existent driver or supplemental paths.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The refactoring successfully addresses the Rubocop offense by breaking down the create_project_package method into smaller, more manageable pieces. However, the two new helper methods introduced (prepare_package_driver_content and prepare_package_supplemental_content) contain highly redundant logic. Consolidating this logic into a single private helper method would improve maintainability and readability. Additionally, since the project uses Sorbet for type checking, adding type signatures to these new methods would ensure consistency with the rest of the codebase.

Comment on lines 632 to 666
def prepare_package_driver_content
package_with_driver = @project.options.test.package_with_driver
driver_path = @project.options.test.driver_path

remote_driver_path = nil
remote_supplemental_path = nil

if package_with_driver && driver_path && File.exist?(driver_path)
remote_driver_path = "#{STUDIO_PACKAGE_ASSETS_PATH}\\Driver"
@logger.info("Uploading driver from '#{driver_path}' to '#{remote_driver_path}'")
@tools.upload_to_studio(driver_path, remote_driver_path)
if package_with_driver && driver_path
if File.exist?(driver_path)
remote_driver_path = "#{STUDIO_PACKAGE_ASSETS_PATH}\\Driver"
@logger.info("Uploading driver from '#{driver_path}' to '#{remote_driver_path}'")
@tools.upload_to_studio(driver_path, remote_driver_path)
else
@logger.warn("Driver path '#{driver_path}' specified, but does not exist, skipping packaging")
end
end

if supplemental_path && File.exist?(supplemental_path)
remote_supplemental_path = "#{STUDIO_PACKAGE_ASSETS_PATH}\\Supplemental"
@logger.info("Uploading supplemental from '#{supplemental_path}' to '#{remote_supplemental_path}'")
@tools.upload_to_studio(supplemental_path, remote_supplemental_path)
remote_driver_path
end

def prepare_package_supplemental_content
supplemental_path = @project.options.test.supplemental_path

remote_supplemental_path = nil
if supplemental_path
if File.exist?(supplemental_path)
remote_supplemental_path = "#{STUDIO_PACKAGE_ASSETS_PATH}\\Supplemental"
@logger.info("Uploading supplemental from '#{supplemental_path}' to '#{remote_supplemental_path}'")
@tools.upload_to_studio(supplemental_path, remote_supplemental_path)
else
@logger.warn("Supplemental path '#{supplemental_path}' specified, but does not exist, skipping packaging")
end
end

remote_supplemental_path
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The methods prepare_package_driver_content and prepare_package_supplemental_content share almost identical logic for checking path existence, logging, and uploading assets. This duplication can be reduced by introducing a shared helper method. Furthermore, adding Sorbet type signatures would maintain consistency with other methods in this class.

    sig { params(type: String, path: T.nilable(String)).returns(T.nilable(String)) }
    def upload_package_asset(type, path)
      return nil unless path

      unless File.exist?(path)
        @logger.warn("#{type} path '#{path}' specified, but does not exist, skipping packaging")
        return nil
      end

      remote_path = "#{STUDIO_PACKAGE_ASSETS_PATH}\\\\#{type}"
      @logger.info("Uploading #{type.downcase} from '#{path}' to '#{remote_path}'")
      @tools.upload_to_studio(path, remote_path)
      remote_path
    end

    sig { returns(T.nilable(String)) }
    def prepare_package_driver_content
      return unless @project.options.test.package_with_driver

      upload_package_asset('Driver', @project.options.test.driver_path)
    end

    sig { returns(T.nilable(String)) }
    def prepare_package_supplemental_content
      upload_package_asset('Supplemental', @project.options.test.supplemental_path)
    end

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the HLK results packaging workflow in AutoHCK::Tests by extracting driver and supplemental upload logic into dedicated helper methods, addressing a RuboCop offense while keeping the packaging behavior intact.

Changes:

  • Extracted driver upload logic into prepare_package_driver_content.
  • Extracted supplemental upload logic into prepare_package_supplemental_content.
  • Updated create_project_package to use the new helpers and to warn when configured paths don’t exist.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
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.

3 participants