Compare commits

...

2 Commits

Author SHA1 Message Date
d0b1341af0
fix(cmd/joj): show valid scopes on wrong message
All checks were successful
build / build (push) Successful in 1m45s
submodules sync / sync (push) Successful in 28s
build / trigger-build-image (push) Successful in 6s
2024-10-08 17:10:48 -04:00
e1e4fded28
feat(cmd/joj): exit 1 on error 2024-10-08 17:08:36 -04:00
2 changed files with 23 additions and 18 deletions

View File

@ -164,15 +164,10 @@ func ParseMsg(confRoot, confName, msg string) (conf Conf, group string, err erro
return
}
func ListValidScopes(confRoot, confName, msg string) ([]string, error) {
conventionalCommit, err := parseConventionalCommit(msg)
if err != nil {
return []string{}, err
}
slog.Info("conventional commit", "commit", conventionalCommit)
func ListValidScopes(confRoot, confName string) ([]string, error) {
confRoot = filepath.Clean(confRoot)
validScopes := []string{}
err = filepath.Walk(confRoot, func(path string, info os.FileInfo, err error) error {
err := filepath.Walk(confRoot, func(path string, info os.FileInfo, err error) error {
if err != nil {
slog.Error("list valid scopes", "error", err)
return err

View File

@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"log/slog"
"os"
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
"github.com/joint-online-judge/JOJ3/cmd/joj3/stage"
@ -25,15 +26,15 @@ func init() {
showVersion = flag.Bool("version", false, "print current version")
}
func main() {
func mainImpl() error {
if err := setupSlog(""); err != nil { // before conf is loaded
slog.Error("setup slog", "error", err)
return
return err
}
flag.Parse()
if *showVersion {
fmt.Println(Version)
return
return nil
}
slog.Info("start joj3", "version", Version)
if msg == "" {
@ -41,31 +42,40 @@ func main() {
msg, err = conf.GetCommitMsg()
if err != nil {
slog.Error("get commit msg", "error", err)
return
return err
}
}
confObj, group, err := conf.ParseMsg(confRoot, confName, msg)
if err != nil {
slog.Error("parse msg", "error", err)
validScopes, scopeErr := conf.ListValidScopes(
confRoot, confName, msg)
confRoot, confName)
if scopeErr != nil {
slog.Error("list valid scopes", "error", scopeErr)
return
return err
}
slog.Info("hint: valid scopes in commit message", "scopes", validScopes)
return
slog.Info("HINT: use valid scopes in commit message",
"valid scopes", validScopes)
return err
}
if err := setupSlog(confObj.LogPath); err != nil { // after conf is loaded
slog.Error("setup slog", "error", err)
return
return err
}
if err := stage.Run(confObj, group); err != nil {
slog.Error("stage run", "error", err)
return
return err
}
if err := teapot.Run(confObj); err != nil {
slog.Error("teapot run", "error", err)
return
return err
}
return nil
}
func main() {
if err := mainImpl(); err != nil {
slog.Error("main exit", "error", err)
os.Exit(1)
}
}