Compare commits

..

No commits in common. "028fd11ab5964b0c106a0ae8cc9f634448ffba87" and "896c4ac2209d5ab9d6eb5cfab7599c2eb98d378d" have entirely different histories.

2 changed files with 12 additions and 18 deletions

View File

@ -226,7 +226,8 @@ func parseMsg(confRoot, confName, msg, tag string) (
} }
slog.Info("conventional commit", "commit", conventionalCommit) slog.Info("conventional commit", "commit", conventionalCommit)
confRoot = filepath.Clean(confRoot) confRoot = filepath.Clean(confRoot)
confPath = filepath.Join(confRoot, conventionalCommit.Scope, confName) confPath = filepath.Clean(fmt.Sprintf("%s/%s/%s",
confRoot, conventionalCommit.Scope, confName))
relPath, err := filepath.Rel(confRoot, confPath) relPath, err := filepath.Rel(confRoot, confPath)
if err != nil { if err != nil {
return return
@ -281,15 +282,14 @@ func hintValidScopes(confRoot, confName string) {
"valid scopes", validScopes) "valid scopes", validScopes)
} }
func GetConfPath(confRoot, confName, fallbackConfName, msg, tag string) ( func GetConfPath(confRoot, confName, msg, tag string) (
confPath, group string, confStat fs.FileInfo, err error, confPath, group string, confStat fs.FileInfo, err error,
) { ) {
confPath, group, err = parseMsg(confRoot, confName, msg, tag) confPath, group, err = parseMsg(confRoot, confName, msg, tag)
if err != nil { if err != nil {
slog.Error("parse msg", "error", err) slog.Error("parse msg", "error", err)
// fallback to conf file in conf root on parse error // fallback to conf file in conf root on parse error
confPath = filepath.Join(confRoot, fallbackConfName) confPath = filepath.Clean(fmt.Sprintf("%s/%s", confRoot, confName))
slog.Info("fallback to conf", "path", confPath)
} }
confStat, err = os.Stat(confPath) confStat, err = os.Stat(confPath)
if err != nil { if err != nil {
@ -298,8 +298,7 @@ func GetConfPath(confRoot, confName, fallbackConfName, msg, tag string) (
} }
slog.Error("stat conf", "error", err) slog.Error("stat conf", "error", err)
// fallback to conf file in conf root on conf not exist // fallback to conf file in conf root on conf not exist
confPath = filepath.Join(confRoot, fallbackConfName) confPath = filepath.Clean(fmt.Sprintf("%s/%s", confRoot, confName))
slog.Info("fallback to conf", "path", confPath)
confStat, err = os.Stat(confPath) confStat, err = os.Stat(confPath)
if err != nil { if err != nil {
slog.Error("stat fallback conf", "error", err) slog.Error("stat fallback conf", "error", err)

View File

@ -14,7 +14,6 @@ import (
var ( var (
confRoot string confRoot string
confName string confName string
fallbackConfName string
tag string tag string
msg string msg string
showVersion *bool showVersion *bool
@ -24,7 +23,6 @@ var (
func init() { func init() {
flag.StringVar(&confRoot, "conf-root", ".", "root path for all config files") flag.StringVar(&confRoot, "conf-root", ".", "root path for all config files")
flag.StringVar(&confName, "conf-name", "conf.json", "filename for config files") flag.StringVar(&confName, "conf-name", "conf.json", "filename for config files")
flag.StringVar(&fallbackConfName, "fallback-conf-name", "", "filename for the fallback config file in conf-root, leave empty to use conf-name")
flag.StringVar(&tag, "tag", "", "tag to trigger the running, when non-empty, should equal to the scope in msg") flag.StringVar(&tag, "tag", "", "tag to trigger the running, when non-empty, should equal to the scope in msg")
// TODO: remove this flag // TODO: remove this flag
flag.StringVar(&msg, "msg", "", "[DEPRECATED] will be ignored") flag.StringVar(&msg, "msg", "", "[DEPRECATED] will be ignored")
@ -41,9 +39,6 @@ func mainImpl() error {
fmt.Println(Version) fmt.Println(Version)
return nil return nil
} }
if fallbackConfName == "" {
fallbackConfName = confName
}
slog.Info("start joj3", "version", Version) slog.Info("start joj3", "version", Version)
msg, err := conf.GetCommitMsg() msg, err := conf.GetCommitMsg()
if err != nil { if err != nil {
@ -51,7 +46,7 @@ func mainImpl() error {
return err return err
} }
confPath, group, confStat, err := conf.GetConfPath( confPath, group, confStat, err := conf.GetConfPath(
confRoot, confName, fallbackConfName, msg, tag) confRoot, confName, msg, tag)
if err != nil { if err != nil {
slog.Error("get conf path", "error", err) slog.Error("get conf path", "error", err)
return err return err