-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathresolver.go
More file actions
64 lines (53 loc) · 1.99 KB
/
Copy pathresolver.go
File metadata and controls
64 lines (53 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cli
import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/github/gh-aw/pkg/console"
"github.com/github/gh-aw/pkg/constants"
"github.com/github/gh-aw/pkg/fileutil"
"github.com/github/gh-aw/pkg/logger"
)
var resolverLog = logger.New("cli:resolver")
// ResolveWorkflowPath resolves a workflow file path from various formats:
// - Absolute path to .md file
// - Relative path to .md file
// - Workflow name or subpath (e.g., "a.md" -> ".github/workflows/a.md", "shared/b.md" -> ".github/workflows/shared/b.md")
func ResolveWorkflowPath(workflowFile string) (string, error) {
resolverLog.Printf("Resolving workflow path: %s", workflowFile)
workflowsDir := constants.GetWorkflowDir()
// Add .md extension if not present
searchPath := workflowFile
if !strings.HasSuffix(searchPath, ".md") {
searchPath += ".md"
}
// 1. If it's a path that exists as-is (absolute or relative), use it
if _, err := os.Stat(searchPath); err == nil {
resolverLog.Printf("Found workflow at direct path: %s", searchPath)
return searchPath, nil
}
// 2. Try exact relative path under .github/workflows
workflowPath := filepath.Join(workflowsDir, searchPath)
if fileutil.FileExists(workflowPath) {
resolverLog.Printf("Found workflow at: %s", workflowPath)
return workflowPath, nil
}
// No matches found - suggest similar workflow names
resolverLog.Printf("Workflow file not found: %s", workflowPath)
suggestions := []string{
fmt.Sprintf("Run '%s status' to see all available workflows", string(constants.CLIExtensionPrefix)),
"Check for typos in the workflow name",
"Ensure the workflow file exists in .github/workflows/",
}
// Add fuzzy match suggestions if available
similarNames := suggestWorkflowNames(searchPath)
if len(similarNames) > 0 {
suggestions = append([]string{fmt.Sprintf("Did you mean: %s?", strings.Join(similarNames, ", "))}, suggestions...)
}
return "", errors.New(console.FormatErrorWithSuggestions(
"workflow file not found: "+workflowPath,
suggestions,
))
}