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

Function findWorkflowsWithSource

pkg/cli/update_workflows.go:171–254  ·  view source on GitHub ↗

findWorkflowsWithSource finds all workflows that have a source field

(workflowsDir string, filterNames []string, verbose bool)

Source from the content-addressed store, hash-verified

169
170// findWorkflowsWithSource finds all workflows that have a source field
171func findWorkflowsWithSource(workflowsDir string, filterNames []string, verbose bool) ([]*workflowWithSource, error) {
172 updateLog.Printf("Finding workflows with source field in %s", workflowsDir)
173 var workflows []*workflowWithSource
174
175 // Read all .md files in workflows directory
176 entries, err := os.ReadDir(workflowsDir)
177 if err != nil {
178 return nil, fmt.Errorf("failed to read workflows directory: %w", err)
179 }
180 updateLog.Printf("Found %d entries in workflows directory", len(entries))
181
182 for _, entry := range entries {
183 if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".md") {
184 continue
185 }
186
187 // Skip .lock.yml files
188 if strings.HasSuffix(entry.Name(), ".lock.yml") {
189 continue
190 }
191
192 workflowPath := filepath.Join(workflowsDir, entry.Name())
193 workflowName := normalizeWorkflowID(entry.Name())
194
195 // Filter by name if specified
196 if len(filterNames) > 0 {
197 matched := false
198 for _, filterName := range filterNames {
199 // Normalize filter name to handle both "workflow" and "workflow.md" formats
200 filterName = normalizeWorkflowID(filterName)
201 if workflowName == filterName {
202 matched = true
203 break
204 }
205 }
206 if !matched {
207 continue
208 }
209 }
210
211 // Read the workflow file and extract source field
212 content, err := os.ReadFile(workflowPath)
213 if err != nil {
214 if verbose {
215 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to read %s: %v", workflowPath, err)))
216 }
217 continue
218 }
219
220 // Parse frontmatter
221 result, err := parser.ExtractFrontmatterFromContent(string(content))
222 if err != nil {
223 if verbose {
224 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to parse frontmatter in %s: %v", workflowPath, err)))
225 }
226 continue
227 }
228

Calls 6

FormatWarningMessageFunction · 0.92
FormatVerboseMessageFunction · 0.92
normalizeWorkflowIDFunction · 0.85
PrintfMethod · 0.45
ErrorfMethod · 0.45