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

Function readSourceRepoFromFile

pkg/cli/helpers.go:71–98  ·  view source on GitHub ↗

readSourceRepoFromFile reads the 'source' frontmatter field from a local workflow file and returns the "owner/repo" portion (e.g. "github/gh-aw"). Returns "" if the file cannot be read, has no source field, or the field is not in the expected format.

(path string)

Source from the content-addressed store, hash-verified

69// and returns the "owner/repo" portion (e.g. "github/gh-aw"). Returns "" if the file
70// cannot be read, has no source field, or the field is not in the expected format.
71func readSourceRepoFromFile(path string) string {
72 helpersLog.Printf("Reading source repo from file: %s", path)
73 content, err := os.ReadFile(path)
74 if err != nil {
75 helpersLog.Printf("Failed to read file: %s", err)
76 return ""
77 }
78 result, err := parser.ExtractFrontmatterFromContent(string(content))
79 if err != nil || result.Frontmatter == nil {
80 return ""
81 }
82 sourceRaw, ok := result.Frontmatter["source"]
83 if !ok {
84 return ""
85 }
86 source, ok := sourceRaw.(string)
87 if !ok || source == "" {
88 return ""
89 }
90 // source format: "owner/repo/path/to/file.md@ref" — extract just "owner/repo"
91 slashParts := strings.SplitN(source, "/", 3)
92 if len(slashParts) < 2 {
93 return ""
94 }
95 repo := slashParts[0] + "/" + slashParts[1]
96 helpersLog.Printf("Extracted source repo: %s", repo)
97 return repo
98}
99
100// sourceRepoLabel returns the source repo string for display in error messages.
101// When the repo string is empty (file has no source field or is not a markdown file),

Calls 2

PrintfMethod · 0.45