MCPcopy Index your code
hub / github.com/cli/cli / FindLegacy

Function FindLegacy

pkg/githubtemplate/github_template.go:58–84  ·  view source on GitHub ↗

FindLegacy returns the file path of the default(legacy) template

(rootDir string, name string)

Source from the content-addressed store, hash-verified

56
57// FindLegacy returns the file path of the default(legacy) template
58func FindLegacy(rootDir string, name string) string {
59 namePattern := regexp.MustCompile(fmt.Sprintf(`(?i)^%s(\.|$)`, strings.ReplaceAll(name, "_", "[_-]")))
60
61 // https://help.github.com/en/github/building-a-strong-community/creating-a-pull-request-template-for-your-repository
62 candidateDirs := []string{
63 path.Join(rootDir, ".github"),
64 rootDir,
65 path.Join(rootDir, "docs"),
66 }
67
68 for _, dir := range candidateDirs {
69 files, err := os.ReadDir(dir)
70 if err != nil {
71 continue
72 }
73 // detect a single template file
74 for _, file := range files {
75 if namePattern.MatchString(file.Name()) &&
76 !file.IsDir() &&
77 file.Type() != fs.ModeSymlink {
78 return path.Join(dir, file.Name())
79 }
80 }
81 }
82
83 return ""
84}
85
86// ExtractName returns the name of the template from YAML front-matter
87func ExtractName(filePath string) string {

Callers 2

fetchMethod · 0.92
TestFindLegacyFunction · 0.85

Calls 3

JoinMethod · 0.80
NameMethod · 0.65
TypeMethod · 0.45

Tested by 1

TestFindLegacyFunction · 0.68