mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-24 21:20:40 +00:00
Merge pull request #30 from bvieira/default-version
Refactor: default version 'source'
This commit is contained in:
commit
48f7fc35f9
@ -52,7 +52,7 @@ func combinedOutputErr(err error, out []byte) error {
|
|||||||
return fmt.Errorf("%v - %s", err, msg[0])
|
return fmt.Errorf("%v - %s", err, msg[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig(filepath string) (Config, error) {
|
func readConfig(filepath string) (Config, error) {
|
||||||
content, rerr := ioutil.ReadFile(filepath)
|
content, rerr := ioutil.ReadFile(filepath)
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
return Config{}, rerr
|
return Config{}, rerr
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Version for git-sv.
|
// Version for git-sv.
|
||||||
var Version = ""
|
var Version = "source"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
configFilename = "config.yml"
|
configFilename = "config.yml"
|
||||||
@ -20,32 +20,7 @@ const (
|
|||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
|
|
||||||
envCfg := loadEnvConfig()
|
cfg := loadCfg()
|
||||||
|
|
||||||
cfg := defaultConfig()
|
|
||||||
|
|
||||||
if envCfg.Home != "" {
|
|
||||||
if homeCfg, err := loadConfig(filepath.Join(envCfg.Home, configFilename)); err == nil {
|
|
||||||
if merr := merge(&cfg, homeCfg); merr != nil {
|
|
||||||
log.Fatal("failed to merge user config, error: ", merr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repoPath, rerr := getRepoPath()
|
|
||||||
if rerr != nil {
|
|
||||||
log.Fatal("failed to get repository path, error: ", rerr)
|
|
||||||
}
|
|
||||||
|
|
||||||
if repoCfg, err := loadConfig(filepath.Join(repoPath, repoConfigFilename)); err == nil {
|
|
||||||
if merr := merge(&cfg, repoCfg); merr != nil {
|
|
||||||
log.Fatal("failed to merge repo config, error: ", merr)
|
|
||||||
}
|
|
||||||
if len(repoCfg.ReleaseNotes.Headers) > 0 { // mergo is merging maps, headers will be overwritten
|
|
||||||
cfg.ReleaseNotes.Headers = repoCfg.ReleaseNotes.Headers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
@ -168,3 +143,33 @@ func main() {
|
|||||||
log.Fatal("failed to run cli, error: ", apperr)
|
log.Fatal("failed to run cli, error: ", apperr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func loadCfg() Config {
|
||||||
|
envCfg := loadEnvConfig()
|
||||||
|
|
||||||
|
cfg := defaultConfig()
|
||||||
|
|
||||||
|
if envCfg.Home != "" {
|
||||||
|
if homeCfg, err := readConfig(filepath.Join(envCfg.Home, configFilename)); err == nil {
|
||||||
|
if merr := merge(&cfg, homeCfg); merr != nil {
|
||||||
|
log.Fatal("failed to merge user config, error: ", merr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repoPath, rerr := getRepoPath()
|
||||||
|
if rerr != nil {
|
||||||
|
log.Fatal("failed to get repository path, 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)
|
||||||
|
}
|
||||||
|
if len(repoCfg.ReleaseNotes.Headers) > 0 { // mergo is merging maps, headers will be overwritten
|
||||||
|
cfg.ReleaseNotes.Headers = repoCfg.ReleaseNotes.Headers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user