0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-21 12:00:40 +00:00

feat: add support to use templates defined on the repository (.sv4git/templates)

issue: #40
This commit is contained in:
Beatriz Vieira 2022-02-06 18:22:54 -03:00
parent 9eaff5d128
commit ef2bc8638a

View File

@ -17,6 +17,7 @@ var Version = "source"
const (
configFilename = "config.yml"
repoConfigFilename = ".sv4git.yml"
configDir = ".sv4git"
)
var (
@ -24,20 +25,28 @@ var (
defaultTemplatesFS embed.FS
)
func templateFS() fs.FS {
func templateFS(filepath string) fs.FS {
if _, err := os.Stat(filepath); err != nil {
defaultTemplatesFS, _ := fs.Sub(defaultTemplatesFS, "resources/templates")
return defaultTemplatesFS
}
return os.DirFS(filepath)
}
func main() {
log.SetFlags(0)
cfg := loadCfg()
repoPath, rerr := getRepoPath()
if rerr != nil {
log.Fatal("failed to discovery repository top level, error: ", rerr)
}
cfg := loadCfg(repoPath)
messageProcessor := sv.NewMessageProcessor(cfg.CommitMessage, cfg.Branches)
git := sv.NewGit(messageProcessor, cfg.Tag)
semverProcessor := sv.NewSemVerCommitsProcessor(cfg.Versioning, cfg.CommitMessage)
releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotes)
outputFormatter := sv.NewOutputFormatter(templateFS())
outputFormatter := sv.NewOutputFormatter(templateFS(filepath.Join(repoPath, configDir, "templates")))
app := cli.NewApp()
app.Name = "sv"
@ -157,7 +166,7 @@ func main() {
}
}
func loadCfg() Config {
func loadCfg(repoPath string) Config {
cfg := defaultConfig()
envCfg := loadEnvConfig()
@ -169,11 +178,6 @@ func loadCfg() Config {
}
}
repoPath, rerr := getRepoPath()
if rerr != nil {
log.Fatal("failed to discovery repository top level, error: ", rerr)
}
if repoCfg, err := readConfig(filepath.Join(repoPath, repoConfigFilename)); err == nil {
if merr := merge(&cfg, repoCfg); merr != nil {
log.Fatal("failed to merge repo config, error: ", merr)