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

Function findWorkflowsByFilenamePattern

pkg/cli/add_interactive_workflow.go:171–212  ·  view source on GitHub ↗

findWorkflowsByFilenamePattern is a helper to find workflows registered in GitHub by filename pattern. The pattern is matched against the workflow filename (basename without extension)

(pattern, repoOverride string, verbose bool)

Source from the content-addressed store, hash-verified

169// findWorkflowsByFilenamePattern is a helper to find workflows registered in GitHub by filename pattern.
170// The pattern is matched against the workflow filename (basename without extension)
171func findWorkflowsByFilenamePattern(pattern, repoOverride string, verbose bool) ([]WorkflowStatus, error) {
172 // This would normally call StatusWorkflows but we need just a simple check
173 // For now, we'll use the gh CLI directly
174 // Request 'path' field so we can match by filename, not by workflow name
175 args := []string{"workflow", "list", "--json", "name,state,path"}
176 if repoOverride != "" {
177 args = append(args, "--repo", repoOverride)
178 }
179
180 if verbose {
181 fmt.Fprintf(os.Stderr, "Running: gh %s\n", strings.Join(args, " "))
182 }
183
184 output, err := workflow.RunGH("Checking workflow status...", args...)
185 if err != nil {
186 if verbose {
187 fmt.Fprintf(os.Stderr, "gh workflow list failed: %v\n", err)
188 }
189 return nil, err
190 }
191
192 if verbose {
193 fmt.Fprintf(os.Stderr, "gh workflow list output: %s\n", string(output))
194 fmt.Fprintf(os.Stderr, "Looking for workflow with filename containing: %s\n", pattern)
195 }
196
197 // Check if any workflow path contains the pattern
198 // The pattern is the workflow name (e.g., "daily-repo-status")
199 // The path is like ".github/workflows/daily-repo-status.lock.yml"
200 // We check if the path contains the pattern
201 if strings.Contains(string(output), pattern+".lock.yml") || strings.Contains(string(output), pattern+".md") {
202 if verbose {
203 fmt.Fprintf(os.Stderr, "Workflow with filename '%s' found in workflow list\n", pattern)
204 }
205 return []WorkflowStatus{{WorkflowListItem: WorkflowListItem{Workflow: pattern}}}, nil
206 }
207
208 if verbose {
209 fmt.Fprintf(os.Stderr, "Workflow with filename '%s' NOT found in workflow list\n", pattern)
210 }
211 return nil, nil
212}

Callers 2

TestGetWorkflowStatusesFunction · 0.85

Calls 1

RunGHFunction · 0.92

Tested by 1

TestGetWorkflowStatusesFunction · 0.68