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

Do not process stack configs when executing command atmos vendor pull and the --stack flag is not specified #740

Merged
merged 13 commits into from
Oct 30, 2024

Conversation

haitham911
Copy link
Collaborator

@haitham911 haitham911 commented Oct 21, 2024

what

  • Do not process stack configs when executing command atmos vendor pull and the --stack flag is not specified
  • Add AtomsValidateOption to checkAtmosConfig to disable or enable check stack

why

  • Atmos vendor should not require stack configs if the stack flag is not provided

references

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced command functionality to handle the "stack" flag, improving CLI configuration initialization.
    • Introduced a new configuration structure for more flexible Atmos configuration checks.
    • Updated the documentation for Atlantis integration, emphasizing support for Terraform Pull Request Automation and providing clearer configuration examples.
  • Bug Fixes

    • Updated error handling to prevent simultaneous processing of conflicting flags ("component" with "stack" and "component" with "tags").
    • Improved clarity of error messages related to CLI configuration initialization failures.
  • Chores

    • Updated dependency versions to ensure the module uses the latest packages.
    • Updated Dockerfile to reflect new versions of the Geodesic and Atmos tools.

@haitham911 haitham911 requested review from a team as code owners October 21, 2024 17:57
Copy link
Contributor

coderabbitai bot commented Oct 21, 2024

Warning

Rate limit exceeded

@aknysh has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 28 minutes and 16 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between ad800b3 and c5e89e4.

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve modifications to the vendorPullCmd command in the cmd/vendor_pull.go file, specifically replacing the previous call to checkAtmosConfig() with a new implementation that includes a parameter for checking the stack. The internal/exec/vendor_utils.go file sees updates to the ExecuteVendorPullCommand function, adding checks for the "stack" flag and refining error handling for conflicting flags. Additionally, the checkAtmosConfig function in cmd/cmd_utils.go has been enhanced for configurability through a new structure and functional options.

Changes

File Path Change Summary
cmd/vendor_pull.go Replaced checkAtmosConfig() with checkAtmosConfig(WithStackValidation(cmd.Flag("stack").Changed)), adding stack flag handling.
internal/exec/vendor_utils.go Updated ExecuteVendorPullCommand to include a check for the "stack" flag and enhanced error handling for conflicting flags.
cmd/cmd_utils.go Introduced ValidateConfig struct, AtmosValidateOption type, and modified checkAtmosConfig to accept options for improved configurability.
examples/quick-start-advanced/Dockerfile Updated GEODESIC_VERSION from 3.2.0 to 3.3.0 and ATMOS_VERSION from 1.93.0 to 1.97.0.
go.mod Updated versions for several dependencies: bubbletea to v1.1.2, lipgloss to v0.13.1, color to v1.18.0, and ansi to v0.4.0.
website/docs/integrations/atlantis.mdx Enhanced documentation for Atlantis integration with Atmos, including new configuration methods and examples.

Possibly related PRs

Suggested labels

no-release

Suggested reviewers

  • hans-d
  • gberenice

Poem

In the burrow where changes bloom,
Flags and commands find more room.
With a hop and a skip, we refine,
Pulling vendors, all in line!
A stack here, a check there,
Our code dances with flair! 🐇✨


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.

@haitham911 haitham911 added the patch A minor, backward compatible change label Oct 21, 2024
@haitham911 haitham911 changed the title Dev 2689 stop process stack with command atmos vendor pull Oct 21, 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: 1

🧹 Outside diff range comments (1)
internal/exec/vendor_utils.go (1)

Line range hint 67-73: LGTM: Improved error handling for conflicting flags

The addition of error handling for conflicting flags is a great improvement. It prevents invalid combinations of flags, making the command more robust and user-friendly. The error messages are clear and informative.

For consistency, consider using the same error formatting style:

-if component != "" && stack != "" {
-    return fmt.Errorf("either '--component' or '--stack' flag can to be provided, but not both")
-}
+if component != "" && stack != "" {
+    return fmt.Errorf("either '--component' or '--stack' flag can be provided, but not both")
+}

-if component != "" && len(tags) > 0 {
-    return fmt.Errorf("either '--component' or '--tags' flag can to be provided, but not both")
-}
+if component != "" && len(tags) > 0 {
+    return fmt.Errorf("either '--component' or '--tags' flag can be provided, but not both")
+}

This change corrects a minor grammatical error and ensures consistency in the error messages.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 7e8d0af and deaf7c3.

📒 Files selected for processing (2)
  • cmd/vendor_pull.go (0 hunks)
  • internal/exec/vendor_utils.go (1 hunks)
💤 Files with no reviewable changes (1)
  • cmd/vendor_pull.go
🧰 Additional context used
🔇 Additional comments (2)
internal/exec/vendor_utils.go (2)

29-30: LGTM: Good addition for flag handling

The introduction of the processStacks variable is a good practice. It allows the function to determine if the "stack" flag was explicitly set by the user, which can be used to control the behavior of the command based on the presence of this flag.


Line range hint 1-1024: Overall assessment: Changes align well with PR objectives

The modifications to ExecuteVendorPullCommand effectively implement the intended behavior changes for the atmos vendor pull command. The introduction of the processStacks flag, its integration with InitCliConfig, and the additional error handling for conflicting flags all contribute to streamlining the command's functionality. These changes ensure that stack configurations are not processed when the stack flag is not provided, aligning perfectly with the PR objectives.

The code quality is good, with clear logic and informative error messages. The suggested minor improvements in error handling and message consistency will further enhance the robustness and user-friendliness of the command.

internal/exec/vendor_utils.go Outdated Show resolved Hide resolved
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: 0

🧹 Outside diff range comments (2)
internal/exec/vendor_utils.go (2)

Line range hint 70-72: Correct grammatical error in error message

The error message contains a grammatical mistake and could be clearer. It currently reads:

return fmt.Errorf("either '--component' or '--stack' flag can to be provided, but not both")

Apply this diff to correct the error message:

-    return fmt.Errorf("either '--component' or '--stack' flag can to be provided, but not both")
+    return fmt.Errorf("only one of '--component' or '--stack' flag can be provided, but not both")

Line range hint 75-77: Correct grammatical error in error message

Similarly, there's a grammatical error in this error message:

return fmt.Errorf("either '--component' or '--tags' flag can to be provided, but not both")

Apply this diff to correct the error message:

-    return fmt.Errorf("either '--component' or '--tags' flag can to be provided, but not both")
+    return fmt.Errorf("only one of '--component' or '--tags' flag can be provided, but not both")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 25bf5af and c8d2af6.

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

40-40: LGTM: Improved error handling with context

The error message now wraps the original error, providing better context for debugging.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between c8d2af6 and 87fe929.

📒 Files selected for processing (2)
  • cmd/cmd_utils.go (2 hunks)
  • cmd/vendor_pull.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
cmd/vendor_pull.go (1)

18-21: Verify validation behavior with WithCheckStack option

While the change aligns with making stack validation conditional, we should verify how WithCheckStack affects other important validations.

✅ Verification successful

Let me gather more context about the validation behavior by checking the ValidateConfig structure and checkAtmosConfig implementation.


Let me check how the CheckStack flag is used in the validation flow to understand its impact on other validations.


Now I have enough context to provide the final response about the validation behavior.

The validation implementation is correct and safe

The changes appropriately handle stack validation while maintaining other essential checks:

  1. The checkAtmosConfig function:
    • Initializes CLI configuration regardless of the stack flag
    • Only skips stack-specific validation when CheckStack is false
    • Still performs basic CLI configuration validation through InitCliConfig

The implementation aligns with both the PR objectives and previous review concerns because:

  • It maintains essential config validation via InitCliConfig
  • Only the stack-specific directory validation is conditional
  • Default behavior (when flag is not provided) skips stack validation, matching PR goals
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for WithCheckStack implementation and its impact on config validation
ast-grep --pattern 'func WithCheckStack($_) $_'
rg -A 10 'WithCheckStack'

Length of output: 1415


Script:

#!/bin/bash
# Search for ValidateConfig structure and checkAtmosConfig implementation
ast-grep --pattern 'type ValidateConfig struct {
  $$$
}'

rg -A 10 'func checkAtmosConfig'

Length of output: 736


Script:

#!/bin/bash
# Search for usage of CheckStack in validation logic
rg -A 10 'CheckStack'

# Search for validation related code in the package
ast-grep --pattern 'func ($_) InitCliConfig($$$)'

Length of output: 2356

cmd/cmd_utils.go (3)

26-30: LGTM!

The WithCheckStack function correctly implements the functional options pattern and follows Go naming conventions.


338-357: LGTM!

The changes correctly implement configurable stack checking while maintaining backward compatibility with the default true value.


338-361: Verify all callers of checkAtmosConfig.

Let's ensure all callers have been updated to handle the new parameter signature.

Additionally, let's verify that the changes align with the PR objectives of not processing stack configurations when using atmos vendor pull without the stack flag.

✅ Verification successful

Let me analyze the results and generate additional verification scripts to get a complete picture.

The first script will help us understand the option type definition and implementation. The second script will check documentation for stack flag usage in vendor pull command. The third script will look for related tests to ensure the behavior is properly tested.


Let me generate one final verification script to understand the vendor pull command implementation better.

These scripts will help us understand how the stack flag is implemented in the vendor pull command and verify the ValidateConfig structure that holds the CheckStack option.


Based on the gathered information, I can now provide the final response:

Changes to checkAtmosConfig are properly implemented

The verification shows that:

  • Only vendor_pull.go uses the new optional parameter WithCheckStack(checkStack), which is correct as it's the only command that needs this flexibility
  • All other 19 callers use the default behavior (no parameters) which maintains the default CheckStack: true setting
  • The ValidateConfig struct and option pattern are properly implemented

The changes align with the PR objectives by allowing the vendor pull command to optionally skip stack validation while maintaining the default behavior for all other commands.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all calls to checkAtmosConfig
rg "checkAtmosConfig\(" --type go

Length of output: 1005


Script:

#!/bin/bash
# Search for the vendor pull command implementation
rg "func.*[Vv]endor.*[Pp]ull" --type go -A 10

Length of output: 2005


Script:

#!/bin/bash
# Let's check the definition of WithCheckStack and AtomsValidateOption
rg "WithCheckStack|type AtomsValidateOption" --type go -A 5

Length of output: 730


Script:

#!/bin/bash
# Let's check the vendor pull command implementation to understand how checkStack is used
rg "vendor pull.*--stack" --type md

Length of output: 37


Script:

#!/bin/bash
# Let's verify if there are any tests for the vendor pull command
rg "TestVendorPull|test.*vendor.*pull" --type go -A 10

Length of output: 56


Script:

#!/bin/bash
# Let's check the vendor pull command implementation and its flags
rg "vendor.*pull.*flags" -B 5 -A 10 --type go

Length of output: 47


Script:

#!/bin/bash
# Check the ValidateConfig struct definition
ast-grep --pattern 'type ValidateConfig struct {
  $$$
}'

Length of output: 218

cmd/vendor_pull.go Outdated Show resolved Hide resolved
cmd/cmd_utils.go Outdated Show resolved Hide resolved
cmd/cmd_utils.go Outdated Show resolved Hide resolved
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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 87fe929 and b2f1d03.

📒 Files selected for processing (2)
  • cmd/cmd_utils.go (2 hunks)
  • cmd/vendor_pull.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
cmd/vendor_pull.go (1)

18-20: Verify core config validation.

While making stack validation optional is correct, we should ensure that essential core config validations (e.g., vending options) are still performed regardless of the --stack flag.

Let's verify how checkAtmosConfig is implemented:

✅ Verification successful

Based on the results, I can now generate the final response since I have enough information about how checkAtmosConfig and core config validation work.

Core config validation is properly maintained independent of stack validation

The implementation shows that core config validation is indeed preserved:

  • Core config validation happens in InitCliConfig which is called unconditionally before any stack validation
  • The checkConfig function (shown in pkg/config/utils.go) validates essential configs like base paths and is called during InitCliConfig
  • Stack validation is properly isolated in a conditional block (if vCfg.CheckStack) and doesn't interfere with core validation
  • The order of operations ensures core validation occurs first, then optional stack validation follows
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if core config validation exists in checkAtmosConfig

# Look for the checkAtmosConfig implementation and its validation logic
ast-grep --pattern 'func checkAtmosConfig($_) {
  $$$
}'

# Search for any core validation patterns
rg -A 5 'validateConfig|checkConfig|configValidation' 

Length of output: 1745

cmd/cmd_utils.go (1)

26-30: LGTM! Clean implementation of functional option.

The function follows Go's functional options pattern correctly and is well-named.

cmd/vendor_pull.go Outdated Show resolved Hide resolved
cmd/cmd_utils.go Outdated Show resolved Hide resolved
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between b2f1d03 and 926fb0f.

📒 Files selected for processing (2)
  • cmd/cmd_utils.go (2 hunks)
  • cmd/vendor_pull.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (3)
cmd/vendor_pull.go (2)

18-19: LGTM! Clear and descriptive comments.

The comments effectively explain the purpose of WithStackValidation and its relationship to the --stack flag.


20-20: 🧹 Nitpick (assertive)

Consider maintaining core config validation.

While making stack validation conditional is correct, we should ensure that essential core configurations (like vending options) are still validated regardless of the --stack flag. This maintains necessary safety checks while addressing the specific stack-related requirement.

Let's verify the current validation behavior:

cmd/cmd_utils.go (1)

28-32: LGTM! Clean implementation of the functional option.

The function follows the functional options pattern correctly and has a clear, descriptive name.

cmd/cmd_utils.go Outdated Show resolved Hide resolved
@osterman osterman requested review from aknysh and removed request for hans-d and nitrocode October 23, 2024 20:03
@aknysh aknysh changed the title stop process stack with command atmos vendor pull Do not process stack configs when executing command atmos vendor pull and the --stack flag is not specified Oct 27, 2024
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

please see comments

@aknysh aknysh removed the patch A minor, backward compatible change label Oct 27, 2024
@aknysh aknysh added minor New features that do not break anything and removed no-release Do not create a new release (wait for additional code changes) labels Oct 29, 2024
osterman
osterman previously approved these changes Oct 29, 2024
@aknysh aknysh added no-release Do not create a new release (wait for additional code changes) and removed minor New features that do not break anything labels Oct 30, 2024
@aknysh aknysh merged commit 682d6e5 into main Oct 30, 2024
23 of 25 checks passed
@aknysh aknysh deleted the DEV-2689 branch October 30, 2024 05:36
Copy link

These changes were released in v1.97.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-release Do not create a new release (wait for additional code changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants