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 workflows #941

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

Implement: atmos list workflows #941

wants to merge 11 commits into from

Conversation

Cerebrovinny
Copy link
Collaborator

@Cerebrovinny Cerebrovinny commented Jan 15, 2025

what

Atmos list workflow with the standard UI

why

Users should be able to list their workflows using this command

Updated 01/16
Screenshot 2025-01-16 at 06 43 59

references

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new CLI command to list Atmos workflows.
    • Introduced workflow listing functionality with optional file filtering.
  • Improvements

    • Enhanced terminal-aware writer for better output formatting.
    • Expanded configuration options for workflow listing.
  • Testing

    • Added comprehensive tests for workflow listing functionality.

The release introduces workflow listing capabilities with enhanced display and configuration options for Atmos users.

@mergify mergify bot added the triage Needs triage label Jan 15, 2025
@osterman
Copy link
Member

  • Can we add some left and right padding to the columns?
  • Demonstrate how it works with no TTY (e.g. in a command pipeline )

@osterman
Copy link
Member

Also add test cases

@osterman osterman added minor New features that do not break anything and removed triage Needs triage labels Jan 16, 2025
@Cerebrovinny
Copy link
Collaborator Author

Also add test cases

Test cases already added here cdd7a1e

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 16, 2025
@Cerebrovinny Cerebrovinny requested a review from osterman January 16, 2025 06:59
@Cerebrovinny Cerebrovinny marked this pull request as ready for review January 16, 2025 06:59
@Cerebrovinny Cerebrovinny requested a review from a team as a code owner January 16, 2025 06:59
Copy link
Contributor

coderabbitai bot commented Jan 16, 2025

📝 Walkthrough

Walkthrough

The pull request introduces a new atmos list workflows command to display workflow information from Atmos configuration files. The implementation spans multiple files, adding functionality to list workflows with support for file filtering, terminal-aware output formatting, and flexible configuration. The changes enable users to view workflow details in a structured, readable format, with graceful fallback to plain text when no terminal support is available.

Changes

File Change Summary
cmd/list_workflows.go Added new listWorkflowsCmd with file filtering flag and workflow listing logic
internal/tui/templates/term/term_writer.go Updated terminal support check using exec.CheckTTYSupport()
pkg/list/list_workflows.go Implemented workflow extraction and listing functions
pkg/list/list_workflows_test.go Added test cases for workflow listing functionality
pkg/schema/schema.go Introduced ListConfig and ListColumnConfig types for workflow listing configuration

Assessment against linked issues

Objective Addressed Explanation
Implement atmos list workflows
Support file filtering
Fallback to plain text without TTY
Configurable columns via schema Partial implementation, more configuration might be needed

Possibly related PRs

  • Trigger workflows from github actions bot #890: The changes in the main PR involve the FilterAndListWorkflows function, which is related to the automation of workflows triggered by GitHub Actions, as seen in the Mergify configuration updates in this PR.

Suggested reviewers

  • aknysh

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

🧹 Nitpick comments (5)
pkg/list/list_workflows_test.go (1)

30-47: Reduce code duplication in tests.

The test configuration and assertions are duplicated between the two test functions. Consider:

  1. Moving the common ListConfig to a test helper
  2. Creating a helper function for common assertions
+func createTestConfig() schema.ListConfig {
+    return schema.ListConfig{
+        Columns: []schema.ListColumnConfig{
+            {Name: "File", Value: "{{ .workflow_file }}"},
+            {Name: "Workflow", Value: "{{ .workflow_name }}"},
+            {Name: "Description", Value: "{{ .workflow_description }}"},
+        },
+    }
+}
+
+func assertWorkflowOutput(t *testing.T, output string) {
+    expected := []string{
+        "File", "Workflow", "Description",
+        "example", "test-1", "Test workflow",
+    }
+    for _, row := range expected {
+        assert.Contains(t, output, row)
+    }
+}
cmd/list_workflows.go (1)

20-22: Enhance command documentation with more examples.

Consider adding examples for:

  • Non-TTY usage (e.g., piping to grep)
  • Different output formats
  • File filtering patterns
-    Example: "atmos list workflows\n" +
-        "atmos list workflows -f <file>",
+    Example: "# List all workflows\n" +
+        "atmos list workflows\n\n" +
+        "# Filter workflows by file\n" +
+        "atmos list workflows -f <file>\n\n" +
+        "# Use with pipes\n" +
+        "atmos list workflows | grep 'pattern'",
pkg/list/list_workflows.go (2)

61-67: Optimize string operations in sorting.

The current implementation concatenates strings repeatedly during sorting, which could be inefficient for large datasets.

-sort.Slice(rows, func(i, j int) bool {
-    return strings.Join(rows[i], "\t") < strings.Join(rows[j], "\t")
-})
+sort.Slice(rows, func(i, j int) bool {
+    // Compare elements sequentially to avoid unnecessary string concatenation
+    for col := 0; col < len(rows[i]); col++ {
+        if rows[i][col] != rows[j][col] {
+            return rows[i][col] < rows[j][col]
+        }
+    }
+    return false
+})

17-18: Add comprehensive documentation for exported functions.

The exported functions need better documentation following Go standards.

-// getWorkflowsFromManifest extracts workflows from a workflow manifest
+// getWorkflowsFromManifest extracts workflows from a workflow manifest and returns them as rows
+// where each row contains [fileName, workflowName, description].
 func getWorkflowsFromManifest(manifest schema.WorkflowManifest) ([][]string, error) {

-// FilterAndListWorkflows filters and lists workflows based on the given file
+// FilterAndListWorkflows filters and lists workflows based on the given file flag.
+// It supports both TTY and non-TTY output formats, automatically degrading to a
+// simple tabular format when TTY is not available. The output format can be
+// customized using the listConfig parameter.
 func FilterAndListWorkflows(fileFlag string, listConfig schema.ListConfig) (string, error) {

Also applies to: 30-31

pkg/schema/schema.go (1)

673-681: LGTM! Well-structured types for list configuration.

The new types ListConfig and ListColumnConfig provide a flexible configuration structure for the workflow listing feature. The Format field will help support different output formats (TTY vs non-TTY), and the column configuration allows for customizable output.

Consider adding Go doc comments to describe:

  • Valid values for the Format field
  • Expected format for the Value field (e.g., if it supports templating)
+// ListConfig defines the configuration for listing workflows
+// Format specifies the output format (e.g., "table", "json")
 type ListConfig struct {
   Format  string             `yaml:"format" json:"format" mapstructure:"format"`
   Columns []ListColumnConfig `yaml:"columns" json:"columns" mapstructure:"columns"`
 }

+// ListColumnConfig defines a column in the workflow list output
+// Value can be a static string or a template expression
 type ListColumnConfig struct {
   Name  string `yaml:"name" json:"name" mapstructure:"name"`
   Value string `yaml:"value" json:"value" mapstructure:"value"`
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 20098bf and fdc63cb.

📒 Files selected for processing (5)
  • cmd/list_workflows.go (1 hunks)
  • internal/tui/templates/term/term_writer.go (2 hunks)
  • pkg/list/list_workflows.go (1 hunks)
  • pkg/list/list_workflows_test.go (1 hunks)
  • pkg/schema/schema.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (3)
internal/tui/templates/term/term_writer.go (1)

34-36: LGTM! Good standardization of TTY support check.

The change to use exec.CheckTTYSupport() aligns with our standardization efforts.

pkg/list/list_workflows.go (1)

38-53: Replace example data with actual workflow manifest loading.

The TODO comment and example data should be replaced with actual implementation.

Let's check if the workflow manifest loading is implemented elsewhere:

Would you like me to help implement the workflow manifest loading functionality or create a GitHub issue to track this?

✅ Verification successful

The workflow manifest loading implementation is indeed missing.

The schema for WorkflowManifest is properly defined in the codebase, but there's no actual implementation for loading workflow manifests from files. The example data should be replaced with proper manifest loading logic.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for workflow manifest loading implementations
rg -l "WorkflowManifest.*Load|LoadWorkflow" --type go

Length of output: 55


Script:

#!/bin/bash
# Search for manifest-related code and configuration loading
echo "=== Searching for manifest-related code ==="
rg -l "manifest" --type go

echo -e "\n=== Searching for YAML/JSON workflow config parsing ==="
rg -l "yaml\.Unmarshal|json\.Unmarshal.*[Ww]orkflow" --type go

echo -e "\n=== Checking schema package for manifest definitions ==="
fd "schema.*\.go$" --exec cat {}

Length of output: 41608

pkg/schema/schema.go (1)

137-138: LGTM! Field addition follows consistent patterns.

The List field is well-structured with appropriate tags, maintaining consistency with other fields in the Workflows struct.

pkg/list/list_workflows_test.go Outdated Show resolved Hide resolved
cmd/list_workflows.go 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

♻️ Duplicate comments (1)
pkg/list/list_workflows_test.go (1)

31-75: 🛠️ Refactor suggestion

Strengthen test coverage with additional test cases.

The test structure is robust, but consider adding these scenarios:

  1. Malformed YAML file to verify error handling
  2. Custom column configuration to verify template rendering
  3. Non-TTY output format (as requested in PR comments)

Here's a suggested addition to the test cases:

 tests := []struct {
     // ... existing fields ...
 }{
     // ... existing test cases ...
+    {
+        name:     "malformed yaml",
+        fileFlag: "testdata/malformed.yaml",
+        config:   schema.ListConfig{},
+        wantErr:  true,
+    },
+    {
+        name:     "custom columns",
+        fileFlag: "",
+        config: schema.ListConfig{
+            Columns: []schema.ListColumnConfig{
+                {Name: "Custom", Value: "{{ .workflow_name | upper }}"},
+            },
+        },
+        contains: []string{"TEST-1"},
+    },
+    {
+        name:     "non-tty output",
+        fileFlag: "",
+        config: schema.ListConfig{
+            Format: "plain",
+        },
+        contains: []string{"test-1\tTest workflow"},
+    },
 }
🧹 Nitpick comments (1)
pkg/list/list_workflows_test.go (1)

11-11: Consider upgrading to yaml.v3 for enhanced security and performance.

The code currently uses gopkg.in/yaml.v2. Version 3 of the yaml package offers better security features and improved performance.

-	"gopkg.in/yaml.v2"
+	"gopkg.in/yaml.v3"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fdc63cb and d63081f.

📒 Files selected for processing (2)
  • pkg/list/list_workflows.go (1 hunks)
  • pkg/list/list_workflows_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/list/list_workflows.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_workflows_test.go (1)

105-144: 🛠️ Refactor suggestion

Refactor test for better structure and stronger assertions.

This test has several opportunities for improvement:

  1. Extract common setup code to avoid duplication
  2. Use structured output verification instead of loose string checks
  3. Verify the exact format and order of the output

Here's a suggested refactor:

+func setupTestWorkflow(t *testing.T) (string, string) {
+    tmpDir, err := os.MkdirTemp("", "workflow_test")
+    require.NoError(t, err)
+    
+    testWorkflowFile := filepath.Join(tmpDir, "test.yaml")
+    // ... existing workflow setup code ...
+    
+    return tmpDir, testWorkflowFile
+}
+
 func TestListWorkflowsWithFile(t *testing.T) {
-    tmpDir, err := os.MkdirTemp("", "workflow_test")
-    require.NoError(t, err)
+    tmpDir, testWorkflowFile := setupTestWorkflow(t)
     defer os.RemoveAll(tmpDir)
-
-    // Create a test workflow file
-    testWorkflowFile := filepath.Join(tmpDir, "test.yaml")
     // ... rest of the setup ...

     output, err := FilterAndListWorkflows(testWorkflowFile, listConfig)
     assert.NoError(t, err)
-    assert.Contains(t, output, "File")
-    assert.Contains(t, output, "Workflow")
-    // ... other Contains checks ...
+    
+    expected := []struct{
+        header string
+        value  string
+    }{
+        {"File", "test.yaml"},
+        {"Workflow", "test-1"},
+        {"Description", "Test workflow"},
+    }
+    
+    for _, e := range expected {
+        headerIdx := strings.Index(output, e.header)
+        valueIdx := strings.Index(output, e.value)
+        assert.Greater(t, valueIdx, headerIdx, 
+            "Value %s should appear after header %s", e.value, e.header)
+    }
 }

Likely invalid or redundant comment.

@osterman
Copy link
Member

  • Please add support for a --format flag. Note, we will be adding this for all list commands.
  • Please add support for --delimiter

Note, if either flag is passed, TTY output is disabled.

See gh CLI for example of format flag.

Comment on lines +85 to +90
rows = lo.UniqBy(rows, func(row []string) string {
return strings.Join(row, "\t")
})
sort.Slice(rows, func(i, j int) bool {
return strings.Join(rows[i], "\t") < strings.Join(rows[j], "\t")
})
Copy link
Member

Choose a reason for hiding this comment

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

Let's support an optional --delimiter flag, that defaults to \t

Headers(header...).
Rows(rows...)

return t.String() + "\n", nil
Copy link
Member

Choose a reason for hiding this comment

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

I think we should use probably the OS new line characters

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 (1)
pkg/schema/schema.go (1)

696-704: Consider adding documentation for the new types.

The ListConfig and ListColumnConfig types are well-structured and follow the codebase patterns. Consider adding documentation comments to describe:

  • The purpose of each type
  • Expected values for the Format field
  • Examples of valid column configurations

Example documentation:

+// ListConfig defines the configuration for list command output formatting
 type ListConfig struct {
     Format  string             `yaml:"format" json:"format" mapstructure:"format"`
     Columns []ListColumnConfig `yaml:"columns" json:"columns" mapstructure:"columns"`
 }

+// ListColumnConfig defines a column in the list output
 type ListColumnConfig struct {
     Name  string `yaml:"name" json:"name" mapstructure:"name"`
     Value string `yaml:"value" json:"value" mapstructure:"value"`
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d63081f and 7bdbbf6.

📒 Files selected for processing (1)
  • pkg/schema/schema.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (1)
pkg/schema/schema.go (1)

160-161: LGTM! Well-structured field addition.

The List field is properly integrated into the Workflows struct with consistent tag formatting.

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
None yet
Development

Successfully merging this pull request may close these issues.

3 participants