0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-21 22:10:39 +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 ( const (
configFilename = "config.yml" configFilename = "config.yml"
repoConfigFilename = ".sv4git.yml" repoConfigFilename = ".sv4git.yml"
configDir = ".sv4git"
) )
var ( var (
@ -24,20 +25,28 @@ var (
defaultTemplatesFS embed.FS defaultTemplatesFS embed.FS
) )
func templateFS() fs.FS { func templateFS(filepath string) fs.FS {
defaultTemplatesFS, _ := fs.Sub(defaultTemplatesFS, "resources/templates") if _, err := os.Stat(filepath); err != nil {
return defaultTemplatesFS defaultTemplatesFS, _ := fs.Sub(defaultTemplatesFS, "resources/templates")
return defaultTemplatesFS
}
return os.DirFS(filepath)
} }
func main() { func main() {
log.SetFlags(0) 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) messageProcessor := sv.NewMessageProcessor(cfg.CommitMessage, cfg.Branches)
git := sv.NewGit(messageProcessor, cfg.Tag) git := sv.NewGit(messageProcessor, cfg.Tag)
semverProcessor := sv.NewSemVerCommitsProcessor(cfg.Versioning, cfg.CommitMessage) semverProcessor := sv.NewSemVerCommitsProcessor(cfg.Versioning, cfg.CommitMessage)
releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotes) releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotes)
outputFormatter := sv.NewOutputFormatter(templateFS()) outputFormatter := sv.NewOutputFormatter(templateFS(filepath.Join(repoPath, configDir, "templates")))
app := cli.NewApp() app := cli.NewApp()
app.Name = "sv" app.Name = "sv"
@ -157,7 +166,7 @@ func main() {
} }
} }
func loadCfg() Config { func loadCfg(repoPath string) Config {
cfg := defaultConfig() cfg := defaultConfig()
envCfg := loadEnvConfig() 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 repoCfg, err := readConfig(filepath.Join(repoPath, repoConfigFilename)); err == nil {
if merr := merge(&cfg, repoCfg); merr != nil { if merr := merge(&cfg, repoCfg); merr != nil {
log.Fatal("failed to merge repo config, error: ", merr) log.Fatal("failed to merge repo config, error: ", merr)