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

Function processWorkflowFileWithInfo

pkg/cli/fix_command.go:275–348  ·  view source on GitHub ↗

processWorkflowFileWithInfo processes a single workflow file and returns detailed fix information

(filePath string, codemods []Codemod, write bool, verbose bool)

Source from the content-addressed store, hash-verified

273
274// processWorkflowFileWithInfo processes a single workflow file and returns detailed fix information
275func processWorkflowFileWithInfo(filePath string, codemods []Codemod, write bool, verbose bool) (bool, []string, error) {
276 fixLog.Printf("Processing workflow file: %s", filePath)
277
278 // Read the file
279 content, err := os.ReadFile(filePath)
280 if err != nil {
281 return false, nil, fmt.Errorf("failed to read file: %w", err)
282 }
283
284 originalContent := string(content)
285 currentContent := originalContent
286
287 // Track what was applied
288 var appliedCodemods []string
289 var hasChanges bool
290
291 // Apply each codemod
292 for _, codemod := range codemods {
293 fixLog.Printf("Attempting codemod: %s", codemod.ID)
294
295 // Re-parse frontmatter for each codemod to get fresh state
296 currentResult, err := parser.ExtractFrontmatterFromContent(currentContent)
297 if err != nil {
298 fixLog.Printf("Failed to parse frontmatter for codemod %s: %v", codemod.ID, err)
299 continue
300 }
301
302 newContent, applied, err := codemod.Apply(currentContent, currentResult.Frontmatter)
303 if err != nil {
304 fixLog.Printf("Codemod %s failed: %v", codemod.ID, err)
305 return false, nil, fmt.Errorf("codemod %s failed: %w", codemod.ID, err)
306 }
307
308 if applied {
309 currentContent = newContent
310 appliedCodemods = append(appliedCodemods, codemod.Name)
311 hasChanges = true
312 fixLog.Printf("Applied codemod: %s", codemod.ID)
313 }
314 }
315
316 // If no changes, report and return
317 if !hasChanges {
318 if verbose {
319 fmt.Fprintf(os.Stderr, "%s\n", console.FormatInfoMessage(fmt.Sprintf(" %s - no fixes needed", filepath.Base(filePath))))
320 }
321 return false, nil, nil
322 }
323
324 // Report changes
325 fileName := filepath.Base(filePath)
326 if write {
327 // Write the file with owner-only read/write permissions (0600) for security best practices
328 if err := os.WriteFile(filePath, []byte(currentContent), constants.FilePermSensitive); err != nil {
329 return false, nil, fmt.Errorf("failed to write file: %w", err)
330 }
331
332 if err := scaffoldSerenaSharedWorkflowIfNeeded(filePath, appliedCodemods, currentContent, verbose); err != nil {

Calls 7

FormatInfoMessageFunction · 0.92
FormatSuccessMessageFunction · 0.92
FormatWarningMessageFunction · 0.92
PrintfMethod · 0.45
ErrorfMethod · 0.45