Skip to content
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

feat: support for .yml and .yaml file extensions for component vendoring #725

Merged

Conversation

RoseSecurity
Copy link
Contributor

@RoseSecurity RoseSecurity commented Oct 15, 2024

what

  • Support for .yml and .yaml when vendoring using component.yaml
  • This change introduces a simple check into

alternative solutions

  1. No modification of the constants, check if component.yaml exists before checking if component.yml exists
	componentConfigFile := path.Join(componentPath, cfg.ComponentVendorConfigFileName)
	if !u.FileExists(componentConfigFile) {
		componentConfigFileYML := path.Join(componentPath, "component.yml")
		if !u.FileExists(componentConfigFileYML) {
			return componentConfig, "", fmt.Errorf("component vendoring config file '%s' or 'component.yml' does not exist in the '%s' folder",
				cfg.ComponentVendorConfigFileName,
				componentPath,
			)
		}
		componentConfigFile = componentConfigFileYML
	}

	componentConfigFileContent, err := os.ReadFile(componentConfigFile)
  1. Modify constant and add helper function
var possibleConfigExtensions = []string{"yaml", "yml"}

func findComponentConfigFile(basePath, fileName string, extensions []string) (string, error) {
    for _, ext := range extensions {
        configFilePath := path.Join(basePath, fmt.Sprintf("%s.%s", fileName, ext))
        if u.FileExists(configFilePath) {
            return configFilePath, nil
        }
    }
    return "", fmt.Errorf("component vendoring config file does not exist in the '%s' folder", basePath)
}

componentConfigFile, err := findComponentConfigFile(componentPath, "component", possibleConfigExtensions)
if err != nil {
    return componentConfig, "", err
}

why

  • The tool is strict about needing component.yaml, file ending for yaml files is a matter of preference and both should be accepted.

testing

  • make build
# component.yml
❯ ./build/atmos vendor pull -c aurora-postgres-resources
Pulling sources for the component 'aurora-postgres-resources' from 'github.com/cloudposse/terraform-aws-components.git//modules/aurora-postgres-resources?ref=1.511.0' into 
'/Users/infra/components/terraform/aurora-postgres-resources'

# component.yaml
❯ ./build/atmos vendor pull -c aurora-postgres-resources
Pulling sources for the component 'aurora-postgres-resources' from 'github.com/cloudposse/terraform-aws-components.git//modules/aurora-postgres-resources?ref=1.511.0' into 
'/Users/infra/components/terraform/aurora-postgres-resources'

# Missing both
❯ ./build/atmos vendor pull -c aurora-postgres-resources
component vendoring config file does not exist in the '/Users/infra/components/terraform/aurora-postgres-resources' folder

references

  • Closes the following issue

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced file existence checks for component configuration, now supporting both .yaml and .yml file formats.
  • Refactor

    • Streamlined variable declarations for improved readability without changing logic.

@osterman
Copy link
Member

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

✅ Actions performed

Full review triggered.

Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve the introduction of a new function, findComponentConfigFile, in the internal/exec/vendor_component_utils.go file. This function enhances the logic for identifying component configuration files by checking for both component.yaml and component.yml extensions. Additionally, the ReadAndProcessComponentVendorConfigFile function has been updated to utilize this new function. Several variable declarations in ExecuteComponentVendorInternal have also been modified for consistency and clarity, using short variable declaration syntax.

Changes

File Change Summary
internal/exec/vendor_component_utils.go Added findComponentConfigFile function to check for component.yaml and component.yml. Updated ReadAndProcessComponentVendorConfigFile to use this function. Modified variable declarations in ExecuteComponentVendorInternal for clarity.

Poem

In the land of code where rabbits play,
We check for files in a brand new way!
With yaml and yml, we’ll never stray,
Streamlined variables brighten our day.
Hops of joy as functions align,
In the garden of code, all works out fine! 🐇✨


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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 94e0226 and 51e759b.

📒 Files selected for processing (1)
  • internal/exec/vendor_component_utils.go (3 hunks)
🧰 Additional context used
🔇 Additional comments (1)
internal/exec/vendor_component_utils.go (1)

Line range hint 1-438: Summary: Changes successfully implement PR objectives with minor suggestions for improvement.

The modifications in this file successfully implement support for both .yaml and .yml file extensions for component vendoring, aligning with the PR objectives. The changes also improve path handling for local files, enhancing the overall functionality of the component vendoring process.

Key improvements:

  1. Added support for component.yml in addition to component.yaml.
  2. Enhanced error messages to include both file extensions.
  3. Improved path handling for local file sources.

Suggestions for further improvement:

  1. Consider using constants for file extensions to improve maintainability.
  2. Add comments to explain the purpose of new logic, especially for local file handling.

Overall, the changes are well-implemented and achieve the desired functionality. The suggested improvements are minor and aimed at enhancing code clarity and maintainability.

internal/exec/vendor_component_utils.go Outdated Show resolved Hide resolved
@osterman
Copy link
Member

@RoseSecurity I like option 2, but defer to @aknysh

@RoseSecurity RoseSecurity changed the title feat: initial support for .yml and .yaml files for component vendoring feat: support for .yml and .yaml file extensions for component vendoring Oct 15, 2024
@aknysh aknysh marked this pull request as ready for review October 16, 2024 05:15
@aknysh aknysh requested review from a team as code owners October 16, 2024 05:15
@aknysh aknysh requested review from kevcube and jamengual October 16, 2024 05:15
@aknysh aknysh added the minor New features that do not break anything label Oct 16, 2024
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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 51e759b and 8f176fa.

📒 Files selected for processing (1)
  • internal/exec/vendor_component_utils.go (4 hunks)
🧰 Additional context used
🔇 Additional comments (2)
internal/exec/vendor_component_utils.go (2)

66-68: LGTM! Changes align with PR objective.

The modification to use findComponentConfigFile correctly implements the support for both .yaml and .yml file extensions. This change is consistent with the new function's implementation and fulfills the PR's objective.


Line range hint 1-450: Overall, the changes successfully implement the PR objectives.

The modifications in this file successfully add support for both .yml and .yaml file extensions for component vendoring. The new findComponentConfigFile function and the updates to ReadAndProcessComponentVendorConfigFile directly address the PR's main objective. Additional changes in ExecuteComponentVendorInternal improve code consistency and enhance local file handling.

The implementation aligns with the second solution discussed in the PR, which proposed modifying a constant and adding a helper function. While the constant wasn't modified, the helper function (findComponentConfigFile) was added to streamline the process of finding the configuration file.

Minor suggestions for adding comments have been made to improve code clarity. Overall, the changes are well-implemented and improve the functionality of the component vendoring process.

internal/exec/vendor_component_utils.go Show resolved Hide resolved
internal/exec/vendor_component_utils.go Show resolved Hide resolved
@aknysh aknysh merged commit 7a25ba3 into cloudposse:main Oct 16, 2024
23 checks passed
Copy link

These changes were released in v1.91.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants