MCPcopy Create free account
hub / github.com/github/gh-aw / GetWorkflowStatuses

Function GetWorkflowStatuses

pkg/cli/status_command.go:43–200  ·  view source on GitHub ↗

GetWorkflowStatuses retrieves workflow status information and returns it as a slice. This function is designed for programmatic access (e.g., from MCP server). For CLI usage, use StatusWorkflows which handles output formatting.

(pattern string, ref string, labelFilter string, repoOverride string)

Source from the content-addressed store, hash-verified

41// This function is designed for programmatic access (e.g., from MCP server).
42// For CLI usage, use StatusWorkflows which handles output formatting.
43func GetWorkflowStatuses(pattern string, ref string, labelFilter string, repoOverride string) ([]WorkflowStatus, error) {
44 statusLog.Printf("Getting workflow statuses: pattern=%s, ref=%s, labelFilter=%s, repo=%s", pattern, ref, labelFilter, repoOverride)
45
46 // Get GitHub workflows data
47 statusLog.Print("Fetching GitHub workflow status")
48 githubWorkflows, err := fetchGitHubWorkflows(repoOverride, false)
49 if err != nil {
50 statusLog.Printf("Failed to fetch GitHub workflows: %v", err)
51 githubWorkflows = make(map[string]*GitHubWorkflow)
52 } else {
53 statusLog.Printf("Successfully fetched %d GitHub workflows", len(githubWorkflows))
54 }
55
56 // Fetch latest workflow runs for ref if specified
57 var latestRunsByWorkflow map[string]*WorkflowRun
58 if ref != "" {
59 latestRunsByWorkflow, err = fetchLatestRunsByRef(ref, repoOverride, false)
60 if err != nil {
61 statusLog.Printf("Failed to fetch workflow runs for ref %s: %v", ref, err)
62 latestRunsByWorkflow = make(map[string]*WorkflowRun)
63 } else {
64 statusLog.Printf("Successfully fetched %d workflow runs for ref %s", len(latestRunsByWorkflow), ref)
65 }
66 }
67
68 // When --repo is specified, build statuses from GitHub API data only.
69 // Local markdown files are not available for a remote repository, so
70 // local-only fields (EngineID, Compiled, TimeRemaining, Labels, On) are
71 // omitted from the results.
72 if repoOverride != "" {
73 // Label metadata is not exposed by the GitHub Actions workflow API, so
74 // filtering by label is not supported when --repo is specified.
75 if labelFilter != "" {
76 return nil, errors.New("--label filter is not supported with --repo: label information is not available from the GitHub Actions API")
77 }
78 return buildRemoteWorkflowStatuses(pattern, githubWorkflows, latestRunsByWorkflow), nil
79 }
80
81 // Local path: discover markdown workflow files from the local filesystem.
82 mdFiles, err := getMarkdownWorkflowFiles("")
83 if err != nil {
84 statusLog.Printf("Failed to get markdown workflow files: %v", err)
85 return nil, fmt.Errorf("failed to get markdown workflow files: %w", err)
86 }
87
88 statusLog.Printf("Found %d markdown workflow files", len(mdFiles))
89 if len(mdFiles) == 0 {
90 return []WorkflowStatus{}, nil
91 }
92
93 // Build status list
94 var statuses []WorkflowStatus
95 for _, file := range mdFiles {
96 base := filepath.Base(file)
97 name := strings.TrimSuffix(base, ".md")
98
99 // Skip if pattern specified and doesn't match
100 if pattern != "" && !strings.Contains(strings.ToLower(name), strings.ToLower(pattern)) {

Calls 15

MarkdownToLockFileFunction · 0.92
FileExistsFunction · 0.92
fetchGitHubWorkflowsFunction · 0.85
fetchLatestRunsByRefFunction · 0.85
getMarkdownWorkflowFilesFunction · 0.85
extractEngineIDFromFileFunction · 0.85
isCompiledUpToDateFunction · 0.85
calculateTimeRemainingFunction · 0.85