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

Implement: atmos list vendor #994

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open

Implement: atmos list vendor #994

wants to merge 48 commits into from

Conversation

Cerebrovinny
Copy link
Collaborator

@Cerebrovinny Cerebrovinny commented Feb 1, 2025

what

Listing all vendor config in tabular way

why

Evidence:
image

Screenshot 2025-02-01 at 19 18 20
Screenshot 2025-02-01 at 19 18 41
Screenshot 2025-02-01 at 19 19 08
Screenshot 2025-02-01 at 19 19 21

references

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a new CLI command that lists vendor configurations with flexible output options including table, JSON, CSV, and TSV.
    • Extended workflow listings to support TSV output, enabling smoother data viewing.
    • Introduced a new field in the vendor configuration for enhanced data management.
    • Added detailed documentation for the atmos list vendor command, including usage examples and output options.
  • Tests

    • Introduced a comprehensive test suite to ensure vendor configuration listings work reliably across various formats.
  • Refactor

    • Enhanced error messages and user feedback during vendor configuration processing for clearer guidance.
    • Improved visibility of the ProcessVendorImports function for better accessibility across packages.

@Cerebrovinny Cerebrovinny marked this pull request as ready for review February 1, 2025 19:22
@Cerebrovinny Cerebrovinny requested a review from a team as a code owner February 1, 2025 19:22
@mergify mergify bot added the triage Needs triage label Feb 1, 2025
Copy link
Contributor

coderabbitai bot commented Feb 1, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a new CLI command (atmos list vendor) along with vendor configuration processing logic and related tests. It adds functions to process vendor files and list vendor configurations in configurable output formats (table, JSON, CSV, TSV). Additionally, the vendor schema is updated with a new field, and workflow listing support is extended with a TSV format. Minor improvements are also made to the error handling and function visibility in the vendor utilities.

Changes

Files Change Summary
cmd/list_vendor.go, pkg/list/list_vendor.go, pkg/list/list_vendor_test.go Added new CLI command listVendorCmd with persistent flags; introduced functions (processVendorFile, FilterAndListVendors) to process vendor configurations; created comprehensive tests for vendor listing based on various output formats.
pkg/schema/schema.go Updated the Vendor struct by adding a new List field with YAML/JSON/mapstructure annotations.
tests/snapshots/.../TestCLICommands_atmos_describe_config.stdout.golden Modified the vendor section to include a new list object with format and columns properties.
pkg/list/list_workflows.go Added a new constant FormatTSV and updated the ValidateFormat function to support TSV output.
internal/exec/vendor_utils.go Renamed processVendorImports to exported ProcessVendorImports and enhanced error messages for vendor configuration validation.

Possibly related PRs

  • Always template vendor source and targets #712: The changes in the main PR, specifically the introduction of the FilterAndListVendors function, are related to the modifications in the retrieved PR, as both involve enhancements to vendor processing logic, although they focus on different aspects of vendor management.
  • get atmos config and vendor from .yaml or .yml #736: The changes in the main PR, specifically the introduction of the FilterAndListVendors function in pkg/list/list_vendor.go, are related to the modifications in the internal/exec/vendor_utils.go file from the retrieved PR, as both involve processing vendor configurations and utilize similar logic for handling vendor data.
  • Fix vendor pull directory creation issue #782: The changes in the main PR, specifically the introduction of the FilterAndListVendors function, are related to the modifications in the retrieved PR that enhance the ReadAndProcessVendorConfigFile function, as both involve processing vendor configurations and handling errors related to vendor files.

Suggested labels

minor

Suggested reviewers

  • osterman

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6921198 and c457166.

📒 Files selected for processing (2)
  • pkg/schema/schema.go (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_describe_config.stdout.golden (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/snapshots/TestCLICommands_atmos_describe_config.stdout.golden
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: [mock-windows] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-windows] examples/demo-vendoring
  • GitHub Check: [mock-windows] examples/demo-component-versions
  • GitHub Check: [k3s] demo-helmfile
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: Summary
🔇 Additional comments (1)
pkg/schema/schema.go (1)

637-640: LGTM! The Vendor struct has been updated with list configuration support.

The addition of the List field enables configurable output formats for vendor listings, which aligns well with the PR objectives.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

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

🧹 Nitpick comments (2)
pkg/list/list_vendor.go (1)

142-144: Sorting strategy could be refined.
Using strings.Join on row columns might not match expected sorting on individual fields.

cmd/list_vendor.go (1)

55-59: Consider direct test coverage.
You may add an integration or CLI test for this command’s flow to ensure consistency.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a6fb9e6 and 13a0665.

📒 Files selected for processing (4)
  • cmd/list_vendor.go (1 hunks)
  • pkg/list/list_vendor.go (1 hunks)
  • pkg/list/list_vendor_test.go (1 hunks)
  • pkg/schema/schema.go (1 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
pkg/list/list_vendor_test.go

111-111: Error return value of os.Chdir is not checked

(errcheck)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: Summary
🔇 Additional comments (6)
pkg/list/list_vendor.go (2)

21-27: Struct layout looks congruent.
No apparent issues with the VendorInfo fields or JSON annotations.


44-55: Validate source component references.
Consider verifying source.Component is non-empty to avoid potential folder creation issues.

cmd/list_vendor.go (1)

15-23: Command usage is concise.
Arguments and examples are clear, supporting multiple formats.

pkg/list/list_vendor_test.go (2)

18-240: Test coverage is thorough.
Your table-driven tests ensure multiple vendor formats are well-exercised.

🧰 Tools
🪛 golangci-lint (1.62.2)

111-111: Error return value of os.Chdir is not checked

(errcheck)


111-111: Defer’s error return is unchecked.
It might be prudent to catch os.Chdir(currentDir) errors in a deferred function.

Proposed fix:

-	defer os.Chdir(currentDir)
+	defer func() {
+		if err := os.Chdir(currentDir); err != nil {
+			t.Logf("Error returning to original directory: %v", err)
+		}
+}()
🧰 Tools
🪛 golangci-lint (1.62.2)

111-111: Error return value of os.Chdir is not checked

(errcheck)

pkg/schema/schema.go (1)

637-638: LGTM! Clean addition of vendor list configuration.

The addition of the List field to the Vendor struct is well-structured and consistent with the existing codebase pattern, reusing the ListConfig type that's already used by the Workflows struct. The field is properly tagged for YAML, JSON, and mapstructure serialization.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 1, 2025
@mergify mergify bot removed the triage Needs triage label Feb 1, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 1, 2025
@mergify mergify bot removed the triage Needs triage label Feb 1, 2025
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

🧹 Nitpick comments (2)
pkg/list/list_vendor_test.go (2)

18-28: Consider extracting test setup into a helper function.

The test setup code is well-structured, but extracting it into a helper function would improve reusability for future test cases.

+func setupTestEnvironment(t *testing.T) (string, func()) {
+    tmpDir, err := os.MkdirTemp("", "vendor_test")
+    require.NoError(t, err)
+    
+    // Create vendor directory structure
+    vendorDir := filepath.Join(tmpDir, "vendor.d")
+    err = os.MkdirAll(vendorDir, 0o755)
+    require.NoError(t, err)
+    
+    return tmpDir, func() {
+        os.RemoveAll(tmpDir)
+    }
+}
+
 func TestListVendors(t *testing.T) {
-    // Create a temporary directory for test files
-    tmpDir, err := os.MkdirTemp("", "vendor_test")
-    require.NoError(t, err)
-    defer os.RemoveAll(tmpDir)
-
-    // Create vendor directory structure
-    vendorDir := filepath.Join(tmpDir, "vendor.d")
-    err = os.MkdirAll(vendorDir, 0o755)
-    require.NoError(t, err)
+    tmpDir, cleanup := setupTestEnvironment(t)
+    defer cleanup()

136-235: Consider adding edge cases to the test suite.

The test cases are well-structured, but consider adding these scenarios:

  1. Empty vendor configuration
  2. Invalid format string
  3. Missing required columns
  4. Special characters in component names

I can help generate the additional test cases if you'd like.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0a99336 and c7c97a2.

📒 Files selected for processing (1)
  • pkg/list/list_vendor_test.go (1 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
pkg/list/list_vendor_test.go

134-134: Error return value of os.Chdir is not checked

(errcheck)

⏰ Context from checks skipped due to timeout of 90000ms (21)
  • GitHub Check: [mock-macos] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-macos] examples/demo-vendoring
  • GitHub Check: [mock-macos] examples/demo-context
  • GitHub Check: [mock-macos] examples/demo-component-versions
  • GitHub Check: [mock-macos] examples/demo-atlantis
  • GitHub Check: [mock-windows] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-windows] examples/demo-vendoring
  • GitHub Check: [mock-windows] examples/demo-context
  • GitHub Check: [mock-windows] examples/demo-component-versions
  • GitHub Check: [mock-windows] examples/demo-atlantis
  • GitHub Check: [mock-linux] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-linux] examples/demo-vendoring
  • GitHub Check: [mock-linux] examples/demo-context
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: [mock-linux] examples/demo-component-versions
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: [k3s] demo-helmfile
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: Docker Lint
  • GitHub Check: Summary
🔇 Additional comments (2)
pkg/list/list_vendor_test.go (2)

1-16: LGTM! Well-organized imports.

The imports are properly organized and include all necessary packages for testing, including JSON handling, file operations, and testing utilities.


237-263: LGTM! Robust test execution.

The test execution follows Go's table-driven test pattern with proper error handling and validation.

@osterman
Copy link
Member

osterman commented Feb 1, 2025

image

Note, csv stands for "Comma Separated Values", but we default to tab. Maybe we should have tsv and csv as presets, and accept --delimiter for everything else.

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

🧹 Nitpick comments (3)
pkg/list/list_vendor.go (3)

21-28: Add field documentation for better code maintainability.

While the struct itself is documented, adding documentation for each field would improve code maintainability.

 // VendorInfo represents a vendor configuration entry
 type VendorInfo struct {
+    // Component is the name of the vendor component
     Component string `json:"component"`
+    // Type indicates the type of vendor configuration
     Type      string `json:"type"`
+    // Manifest is the path to the vendor manifest file
     Manifest  string `json:"manifest"`
+    // Folder is the path to the component folder
     Folder    string `json:"folder"`
+    // Version specifies the version of the vendor component
     Version   string `json:"version"`
 }

144-147: Improve sort function reliability.

The current sort implementation could produce unexpected results when the delimiter appears in the data.

-    sort.Slice(rows, func(i, j int) bool {
-        return strings.Join(rows[i], delimiter) < strings.Join(rows[j], delimiter)
-    })
+    sort.Slice(rows, func(i, j int) bool {
+        // Compare by component first, then by type
+        if rows[i][0] != rows[j][0] {
+            return rows[i][0] < rows[j][0]
+        }
+        return rows[i][1] < rows[j][1]
+    })

171-188: Extract table styling logic for better maintainability.

The table styling code should be extracted into a separate function for better organization.

+func createStyledTable(header []string, rows [][]string) string {
+    t := table.New().
+        Border(lipgloss.ThickBorder()).
+        BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color(theme.ColorBorder))).
+        StyleFunc(func(row, col int) lipgloss.Style {
+            style := lipgloss.NewStyle().PaddingLeft(1).PaddingRight(1)
+            if row == 0 {
+                return style.Inherit(theme.Styles.CommandName).Align(lipgloss.Center)
+            }
+            return style.Inherit(theme.Styles.Description)
+        }).
+        Headers(header...).
+        Rows(rows...)
+    return t.String() + utils.GetLineEnding()
+}
+
 // In FilterAndListVendors:
     if format == "" && exec.CheckTTYSupport() {
-        // Create a styled table for TTY
-        t := table.New().
-            Border(lipgloss.ThickBorder()).
-            // ... rest of the table styling code ...
-        return t.String() + utils.GetLineEnding(), nil
+        return createStyledTable(header, rows), nil
     }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7c97a2 and 359802a.

📒 Files selected for processing (2)
  • pkg/list/list_vendor.go (1 hunks)
  • pkg/list/list_vendor_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/list/list_vendor_test.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (1)
pkg/list/list_vendor.go (1)

1-19: LGTM! Well-organized imports.

The imports are properly organized and all are being used in the code.

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

🧹 Nitpick comments (2)
pkg/list/list_workflows.go (2)

26-26: Consider enhancing format-specific delimiter handling.

The addition of FormatTSV is a good step, but we should ensure consistent delimiter handling between CSV and TSV formats.

Consider defining format-specific delimiters as constants and using them in the format handling logic:

 const (
 	FormatTable = "table"
 	FormatJSON  = "json"
 	FormatCSV   = "csv"
 	FormatTSV   = "tsv"
+	DelimiterCSV = ","
+	DelimiterTSV = "\t"
 )

Also applies to: 34-34


192-199: Enhance format-specific output handling.

The current implementation uses the same logic for both CSV and TSV formats. Consider separating these cases to handle format-specific requirements.

Consider updating the format handling:

 	switch format {
 	case "json":
 		// ... existing JSON handling ...
 	case "csv":
-		// Use the provided delimiter for CSV output
+		// Use comma delimiter for CSV unless custom delimiter provided
+		csvDelimiter := DelimiterCSV
+		if delimiter != "" {
+			csvDelimiter = delimiter
+		}
 		var output strings.Builder
-		output.WriteString(strings.Join(header, delimiter) + utils.GetLineEnding())
+		output.WriteString(strings.Join(header, csvDelimiter) + utils.GetLineEnding())
 		for _, row := range rows {
-			output.WriteString(strings.Join(row, delimiter) + utils.GetLineEnding())
+			output.WriteString(strings.Join(row, csvDelimiter) + utils.GetLineEnding())
 		}
 		return output.String(), nil
+	case "tsv":
+		// Use tab delimiter for TSV unless custom delimiter provided
+		tsvDelimiter := DelimiterTSV
+		if delimiter != "" {
+			tsvDelimiter = delimiter
+		}
+		var output strings.Builder
+		output.WriteString(strings.Join(header, tsvDelimiter) + utils.GetLineEnding())
+		for _, row := range rows {
+			output.WriteString(strings.Join(row, tsvDelimiter) + utils.GetLineEnding())
+		}
+		return output.String(), nil
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 359802a and 32eb1e8.

📒 Files selected for processing (3)
  • cmd/list_vendor.go (1 hunks)
  • pkg/list/list_vendor.go (1 hunks)
  • pkg/list/list_workflows.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/list/list_vendor.go
  • cmd/list_vendor.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 2, 2025
@mergify mergify bot removed the triage Needs triage label Feb 2, 2025
@mergify mergify bot added the triage Needs triage label Feb 14, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 14, 2025
@mergify mergify bot removed the triage Needs triage label Feb 14, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 15, 2025
@mergify mergify bot removed the triage Needs triage label Feb 15, 2025
@mergify mergify bot removed the triage Needs triage label Feb 15, 2025
@aknysh aknysh added the no-release Do not create a new release (wait for additional code changes) label Feb 18, 2025
}

// FilterAndListVendors lists vendor configurations based on the provided configuration
func FilterAndListVendors(listConfig schema.ListConfig, format string, delimiter string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Please refactor into smaller functions. Under 50 lines long, with 10-30 ideal.

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