FindLegacy returns the file path of the default(legacy) template
(rootDir string, name string)
| 56 | |
| 57 | // FindLegacy returns the file path of the default(legacy) template |
| 58 | func 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 |
| 87 | func ExtractName(filePath string) string { |