feat: match empty groups to empty groups
All checks were successful
submodules sync / sync (push) Successful in 1m7s
build / build (push) Successful in 2m54s
build / trigger-build-image (push) Successful in 14s

This commit is contained in:
张泊明518370910136 2025-10-21 14:21:58 -07:00
parent 8739504d45
commit 9321218181
No known key found for this signature in database
GPG Key ID: 134DACA8458EB0E3
3 changed files with 20 additions and 17 deletions

View File

@ -21,18 +21,18 @@ import (
func GetCommitMsg() (msg string, err error) {
r, err := git.PlainOpen(".")
if err != nil {
return
return msg, err
}
ref, err := r.Head()
if err != nil {
return
return msg, err
}
commit, err := r.CommitObject(ref.Hash())
if err != nil {
return
return msg, err
}
msg = commit.Message
return
return msg, err
}
func parseConventionalCommit(commit string) (*ConventionalCommit, error) {
@ -62,20 +62,20 @@ func ParseConfFile(path string) (conf *Conf, err error) {
d.Validator = multiconfig.MultiValidator(&multiconfig.RequiredValidator{})
if err = d.Load(conf); err != nil {
slog.Error("parse stages conf", "error", err)
return
return conf, err
}
if err = d.Validate(conf); err != nil {
slog.Error("validate stages conf", "error", err)
return
return conf, err
}
return
return conf, err
}
func GetSHA256(filePath string) (hashStr string, err error) {
// Open the file
file, err := os.Open(filePath)
if err != nil {
return
return hashStr, err
}
defer func() {
if cerr := file.Close(); cerr != nil && err == nil {
@ -86,7 +86,7 @@ func GetSHA256(filePath string) (hashStr string, err error) {
// Calculate SHA-256
hash := sha256.New()
if _, err = io.Copy(hash, file); err != nil {
return
return hashStr, err
}
hashStr = hex.EncodeToString(hash.Sum(nil))
return hashStr, nil
@ -99,7 +99,7 @@ func parseMsg(confRoot, confName, msg, tag string) (
if tag == "" {
conventionalCommit, err = parseConventionalCommit(msg)
if err != nil {
return
return confPath, conventionalCommit, err
}
} else {
conventionalCommit = &ConventionalCommit{
@ -112,13 +112,13 @@ func parseMsg(confRoot, confName, msg, tag string) (
confPath = filepath.Join(confRoot, conventionalCommit.Scope, confName)
relPath, err := filepath.Rel(confRoot, confPath)
if err != nil {
return
return confPath, conventionalCommit, err
}
if strings.HasPrefix(relPath, "..") || filepath.IsAbs(relPath) {
err = fmt.Errorf("invalid scope as path: %s", conventionalCommit.Scope)
return
return confPath, conventionalCommit, err
}
return
return confPath, conventionalCommit, err
}
func hintValidScopes(confRoot, confName string) {

View File

@ -44,8 +44,8 @@ func generateStages(confStages []conf.ConfStage, groups []string) (
stages := []stage.Stage{}
existNames := map[string]bool{}
for i, s := range confStages {
if s.Name == "" {
s.Name = fmt.Sprintf("stage-%d", i)
if len(groups) == 0 && (len(s.Groups) != 0 || s.Group != "") {
continue
}
ok := false
if s.Group == "" && len(s.Groups) == 0 {
@ -75,6 +75,9 @@ func generateStages(confStages []conf.ConfStage, groups []string) (
if !ok && len(groups) > 0 {
continue
}
if s.Name == "" {
s.Name = fmt.Sprintf("stage-%d", i)
}
_, ok = existNames[s.Name] // check for existence
if ok {
continue

View File

@ -21,9 +21,9 @@ func Run(conf Conf) (res Result, err error) {
// If there are more kinds of errors need to be handled separately, add
// more fields in the Result struct, don't mess everything up in Stderr.
err = fmt.Errorf("sample negative score: %d", conf.Score)
return
return res, err
}
res.Score = conf.Score
res.Comment = "sample comment"
return
return res, err
}