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

Function resolveWorkflowFileInDir

pkg/cli/workflows.go:496–555  ·  view source on GitHub ↗
(fileOrWorkflowName string, verbose bool, workflowDir string)

Source from the content-addressed store, hash-verified

494}
495
496func resolveWorkflowFileInDir(fileOrWorkflowName string, verbose bool, workflowDir string) (string, error) {
497 // First, try to use it as a direct file path
498 if _, err := os.Stat(fileOrWorkflowName); err == nil {
499 workflowsLog.Printf("Found workflow file at path: %s", fileOrWorkflowName)
500 console.LogVerbose(verbose, "Found workflow file at path: "+fileOrWorkflowName)
501 // Return absolute path
502 absPath, err := filepath.Abs(fileOrWorkflowName)
503 if err != nil {
504 return fileOrWorkflowName, nil // fallback to original path
505 }
506 return absPath, nil
507 }
508
509 // If it's not a direct file path, try to resolve it as a workflow name
510 workflowsLog.Printf("File not found at %s, trying to resolve as workflow name", fileOrWorkflowName)
511
512 // Add .md extension if not present
513 workflowPath := fileOrWorkflowName
514 if !strings.HasSuffix(workflowPath, ".md") {
515 workflowPath += ".md"
516 }
517
518 workflowsLog.Printf("Looking for workflow file: %s", workflowPath)
519
520 // Use provided directory or default
521 workflowsDir := workflowDir
522 if workflowsDir == "" {
523 workflowsDir = getWorkflowsDir()
524 }
525
526 // Try to find the workflow in local sources only (not packages)
527 _, path, err := readWorkflowFile(workflowPath, workflowsDir)
528 if err != nil {
529 suggestions := []string{
530 fmt.Sprintf("Run '%s status' to see all available workflows", string(constants.CLIExtensionPrefix)),
531 fmt.Sprintf("Create a new workflow with '%s new %s'", string(constants.CLIExtensionPrefix), fileOrWorkflowName),
532 "Check for typos in the workflow name",
533 }
534
535 // Add fuzzy match suggestions
536 similarNames := suggestWorkflowNames(fileOrWorkflowName)
537 if len(similarNames) > 0 {
538 suggestions = append([]string{fmt.Sprintf("Did you mean: %s?", strings.Join(similarNames, ", "))}, suggestions...)
539 }
540
541 return "", errors.New(console.FormatErrorWithSuggestions(
542 fmt.Sprintf("workflow '%s' not found in local .github/workflows", fileOrWorkflowName),
543 suggestions,
544 ))
545 }
546
547 workflowsLog.Print("Found workflow in local .github/workflows")
548
549 // Return absolute path
550 absPath, err := filepath.Abs(path)
551 if err != nil {
552 return path, nil // fallback to original path
553 }

Callers 2

runFixCommandFunction · 0.85
resolveWorkflowFileFunction · 0.85

Calls 7

LogVerboseFunction · 0.92
getWorkflowsDirFunction · 0.85
readWorkflowFileFunction · 0.85
suggestWorkflowNamesFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45

Tested by

no test coverage detected