feat: hint valid scopes
This commit is contained in:
parent
64ae632003
commit
5c2fe4ffcb
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -140,3 +141,31 @@ func parseMsg(confRoot, confName, msg string) (conf Conf, group string, err erro
|
||||||
slog.Debug("conf loaded", "conf", conf)
|
slog.Debug("conf loaded", "conf", conf)
|
||||||
return
|
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)
|
||||||
|
confRoot = filepath.Clean(confRoot)
|
||||||
|
validScopes := []string{}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
if info.IsDir() {
|
||||||
|
confPath := filepath.Join(path, confName)
|
||||||
|
if _, err := os.Stat(confPath); err == nil {
|
||||||
|
relPath, err := filepath.Rel(confRoot, path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
validScopes = append(validScopes, relPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return validScopes, err
|
||||||
|
}
|
||||||
|
|
|
@ -122,6 +122,13 @@ func mainImpl() error {
|
||||||
conf, group, err := parseMsg(confRoot, confName, msg)
|
conf, group, err := parseMsg(confRoot, confName, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("parse msg", "error", err)
|
slog.Error("parse msg", "error", err)
|
||||||
|
validScopes, scopeErr := listValidScopes(
|
||||||
|
confRoot, confName, msg)
|
||||||
|
if scopeErr != nil {
|
||||||
|
slog.Error("list valid scopes", "error", scopeErr)
|
||||||
|
return scopeErr
|
||||||
|
}
|
||||||
|
slog.Info("hint: valid scopes in commit message", "scopes", validScopes)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := setupSlog(conf.LogPath); err != nil { // after conf is loaded
|
if err := setupSlog(conf.LogPath); err != nil { // after conf is loaded
|
||||||
|
|
Loading…
Reference in New Issue
Block a user