MCPcopy
hub / github.com/cli/cli / FindNonLegacy

Function FindNonLegacy

pkg/githubtemplate/github_template.go:16–55  ·  view source on GitHub ↗

FindNonLegacy returns the list of template file paths from the template folder (according to the "upgraded multiple template builder")

(rootDir string, name string)

Source from the content-addressed store, hash-verified

14
15// FindNonLegacy returns the list of template file paths from the template folder (according to the "upgraded multiple template builder")
16func FindNonLegacy(rootDir string, name string) []string {
17 results := []string{}
18
19 // https://help.github.com/en/github/building-a-strong-community/creating-a-pull-request-template-for-your-repository
20 candidateDirs := []string{
21 path.Join(rootDir, ".github"),
22 rootDir,
23 path.Join(rootDir, "docs"),
24 }
25
26mainLoop:
27 for _, dir := range candidateDirs {
28 files, err := os.ReadDir(dir)
29 if err != nil {
30 continue
31 }
32 // detect multiple templates in a subdirectory
33 for _, file := range files {
34 if strings.EqualFold(file.Name(), name) && file.IsDir() {
35 templates, err := os.ReadDir(path.Join(dir, file.Name()))
36 if err != nil {
37 break
38 }
39 for _, tf := range templates {
40 if strings.HasSuffix(tf.Name(), ".md") &&
41 file.Type() != fs.ModeSymlink {
42 results = append(results, path.Join(dir, file.Name(), tf.Name()))
43 }
44 }
45 if len(results) > 0 {
46 break mainLoop
47 }
48 break
49 }
50 }
51 }
52
53 sort.Strings(results)
54 return results
55}
56
57// FindLegacy returns the file path of the default(legacy) template
58func FindLegacy(rootDir string, name string) string {

Callers 2

fetchMethod · 0.92
TestFindNonLegacyFunction · 0.85

Calls 3

JoinMethod · 0.80
NameMethod · 0.65
TypeMethod · 0.45

Tested by 1

TestFindNonLegacyFunction · 0.68