Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/issue-classifier.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .github/workflows/release.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/stale-repo-identifier.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/super-linter.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pkg/cli/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestRemoveWorkflows(t *testing.T) {
}

func TestStatusWorkflows(t *testing.T) {
err := StatusWorkflows("test-pattern", false, false, "", "")
err := StatusWorkflows("test-pattern", false, false, "", "", "")

// Should not error since it's a stub implementation
if err != nil {
Expand Down Expand Up @@ -421,10 +421,10 @@ Test workflow for command existence.`
_, err := CompileWorkflows(config)
return err
}, false, "CompileWorkflows"},
{func() error { return RemoveWorkflows("nonexistent", false) }, false, "RemoveWorkflows"}, // Should handle missing directory gracefully
{func() error { return StatusWorkflows("nonexistent", false, false, "", "") }, false, "StatusWorkflows"}, // Should handle missing directory gracefully
{func() error { return EnableWorkflows("nonexistent") }, true, "EnableWorkflows"}, // Should now error when no workflows found to enable
{func() error { return DisableWorkflows("nonexistent") }, true, "DisableWorkflows"}, // Should now also error when no workflows found to disable
{func() error { return RemoveWorkflows("nonexistent", false) }, false, "RemoveWorkflows"}, // Should handle missing directory gracefully
{func() error { return StatusWorkflows("nonexistent", false, false, "", "", "") }, false, "StatusWorkflows"}, // Should handle missing directory gracefully
{func() error { return EnableWorkflows("nonexistent") }, true, "EnableWorkflows"}, // Should now error when no workflows found to enable
{func() error { return DisableWorkflows("nonexistent") }, true, "DisableWorkflows"}, // Should now also error when no workflows found to disable
{func() error {
return RunWorkflowOnGitHub("", false, "", "", "", false, false, false, []string{}, false)
}, true, "RunWorkflowOnGitHub"}, // Should error with empty workflow name
Expand Down
15 changes: 9 additions & 6 deletions pkg/cli/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ and time remaining until expiration (if stop-after is configured).
The optional pattern argument filters workflows by name (case-insensitive substring match).

Examples:
` + constants.CLIExtensionPrefix + ` status # Show all workflow status
` + constants.CLIExtensionPrefix + ` status ci- # Show workflows with 'ci-' in name
` + constants.CLIExtensionPrefix + ` status --json # Output in JSON format
` + constants.CLIExtensionPrefix + ` status --ref main # Show latest run status for main branch
` + constants.CLIExtensionPrefix + ` status --label automation # Show workflows with 'automation' label`,
` + constants.CLIExtensionPrefix + ` status # Show all workflow status
` + constants.CLIExtensionPrefix + ` status ci- # Show workflows with 'ci-' in name
` + constants.CLIExtensionPrefix + ` status --json # Output in JSON format
` + constants.CLIExtensionPrefix + ` status --ref main # Show latest run status for main branch
` + constants.CLIExtensionPrefix + ` status --label automation # Show workflows with 'automation' label
` + constants.CLIExtensionPrefix + ` status --repo owner/other-repo # Check status in different repository`,
RunE: func(cmd *cobra.Command, args []string) error {
var pattern string
if len(args) > 0 {
Expand All @@ -32,11 +33,13 @@ Examples:
jsonFlag, _ := cmd.Flags().GetBool("json")
ref, _ := cmd.Flags().GetString("ref")
labelFilter, _ := cmd.Flags().GetString("label")
return StatusWorkflows(pattern, verbose, jsonFlag, ref, labelFilter)
repoOverride, _ := cmd.Flags().GetString("repo")
return StatusWorkflows(pattern, verbose, jsonFlag, ref, labelFilter, repoOverride)
},
}

addJSONFlag(cmd)
cmd.Flags().StringP("repo", "r", "", "Target repository (owner/repo format). Defaults to current repository")
cmd.Flags().String("ref", "", "Filter runs by branch or tag name (e.g., main, v1.0.0)")
cmd.Flags().String("label", "", "Filter workflows by label")

Expand Down
15 changes: 9 additions & 6 deletions pkg/cli/status_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type WorkflowStatus struct {
RunConclusion string `json:"run_conclusion,omitempty" console:"header:Run Conclusion,omitempty"`
}

func StatusWorkflows(pattern string, verbose bool, jsonOutput bool, ref string, labelFilter string) error {
statusLog.Printf("Checking workflow status: pattern=%s, jsonOutput=%v, ref=%s, labelFilter=%s", pattern, jsonOutput, ref, labelFilter)
func StatusWorkflows(pattern string, verbose bool, jsonOutput bool, ref string, labelFilter string, repoOverride string) error {
statusLog.Printf("Checking workflow status: pattern=%s, jsonOutput=%v, ref=%s, labelFilter=%s, repo=%s", pattern, jsonOutput, ref, labelFilter, repoOverride)
if verbose && !jsonOutput {
fmt.Printf("Checking status of workflow files\n")
if pattern != "" {
Expand Down Expand Up @@ -66,7 +66,7 @@ func StatusWorkflows(pattern string, verbose bool, jsonOutput bool, ref string,

// Get GitHub workflows data
statusLog.Print("Fetching GitHub workflow status")
githubWorkflows, err := fetchGitHubWorkflows("", verbose && !jsonOutput)
githubWorkflows, err := fetchGitHubWorkflows(repoOverride, verbose && !jsonOutput)
if err != nil {
statusLog.Printf("Failed to fetch GitHub workflows: %v", err)
if verbose && !jsonOutput {
Expand All @@ -89,7 +89,7 @@ func StatusWorkflows(pattern string, verbose bool, jsonOutput bool, ref string,
if verbose && !jsonOutput {
fmt.Printf("Fetching latest runs for ref: %s\n", ref)
}
latestRunsByWorkflow, err = fetchLatestRunsByRef(ref, verbose && !jsonOutput)
latestRunsByWorkflow, err = fetchLatestRunsByRef(ref, repoOverride, verbose && !jsonOutput)
if err != nil {
statusLog.Printf("Failed to fetch workflow runs for ref %s: %v", ref, err)
if verbose && !jsonOutput {
Expand Down Expand Up @@ -454,8 +454,8 @@ func extractEngineIDFromFile(filePath string) string {
}

// fetchLatestRunsByRef fetches the latest workflow run for each workflow from a specific ref (branch or tag)
func fetchLatestRunsByRef(ref string, verbose bool) (map[string]*WorkflowRun, error) {
statusLog.Printf("Fetching latest workflow runs for ref: %s", ref)
func fetchLatestRunsByRef(ref string, repoOverride string, verbose bool) (map[string]*WorkflowRun, error) {
statusLog.Printf("Fetching latest workflow runs for ref: %s, repo: %s", ref, repoOverride)

// Start spinner for network operation (only if not in verbose mode)
spinner := console.NewSpinner("Fetching workflow runs for ref...")
Expand All @@ -465,6 +465,9 @@ func fetchLatestRunsByRef(ref string, verbose bool) (map[string]*WorkflowRun, er

// Fetch workflow runs for the ref (uses --branch flag which also works for tags)
args := []string{"run", "list", "--branch", ref, "--json", "databaseId,number,url,status,conclusion,workflowName,createdAt,headBranch", "--limit", "100"}
if repoOverride != "" {
args = append(args, "--repo", repoOverride)
}
cmd := workflow.ExecGH(args...)
output, err := cmd.Output()

Expand Down
20 changes: 18 additions & 2 deletions pkg/cli/status_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestStatusWorkflows_JSONOutput(t *testing.T) {

// Test JSON output without pattern
t.Run("JSON output without pattern", func(t *testing.T) {
err := StatusWorkflows("", false, true, "", "")
err := StatusWorkflows("", false, true, "", "", "")
if err != nil {
t.Errorf("StatusWorkflows with JSON flag failed: %v", err)
}
Expand All @@ -38,7 +38,7 @@ func TestStatusWorkflows_JSONOutput(t *testing.T) {

// Test JSON output with pattern
t.Run("JSON output with pattern", func(t *testing.T) {
err := StatusWorkflows("smoke", false, true, "", "")
err := StatusWorkflows("smoke", false, true, "", "", "")
if err != nil {
t.Errorf("StatusWorkflows with JSON flag and pattern failed: %v", err)
}
Expand Down Expand Up @@ -513,3 +513,19 @@ func TestWorkflowStatus_ConsoleRenderingWithRunStatus(t *testing.T) {
}
}
}

// TestStatusWorkflows_WithRepoOverride tests that the repoOverride parameter is accepted
func TestStatusWorkflows_WithRepoOverride(t *testing.T) {
// This test verifies that the function accepts the repoOverride parameter
// and doesn't error out. It should work in the current repository context.
err := StatusWorkflows("", false, true, "", "", "")
if err != nil {
t.Errorf("StatusWorkflows with empty repoOverride should not error: %v", err)
}

// Test with a non-empty repo override (will fail gracefully if repo doesn't exist)
// We expect this to either succeed or fail gracefully without panicking
_ = StatusWorkflows("", false, true, "", "", "nonexistent/repo")
// Note: We don't check error here because it's expected to fail for a nonexistent repo
// The important part is that the parameter is accepted and used
}