FindNonLegacy returns the list of template file paths from the template folder (according to the "upgraded multiple template builder")
(rootDir string, name string)
| 14 | |
| 15 | // FindNonLegacy returns the list of template file paths from the template folder (according to the "upgraded multiple template builder") |
| 16 | func 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 | |
| 26 | mainLoop: |
| 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 |
| 58 | func FindLegacy(rootDir string, name string) string { |