feat: match empty groups to empty groups
This commit is contained in:
parent
8739504d45
commit
9321218181
|
|
@ -21,18 +21,18 @@ import (
|
||||||
func GetCommitMsg() (msg string, err error) {
|
func GetCommitMsg() (msg string, err error) {
|
||||||
r, err := git.PlainOpen(".")
|
r, err := git.PlainOpen(".")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return msg, err
|
||||||
}
|
}
|
||||||
ref, err := r.Head()
|
ref, err := r.Head()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return msg, err
|
||||||
}
|
}
|
||||||
commit, err := r.CommitObject(ref.Hash())
|
commit, err := r.CommitObject(ref.Hash())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return msg, err
|
||||||
}
|
}
|
||||||
msg = commit.Message
|
msg = commit.Message
|
||||||
return
|
return msg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseConventionalCommit(commit string) (*ConventionalCommit, error) {
|
func parseConventionalCommit(commit string) (*ConventionalCommit, error) {
|
||||||
|
|
@ -62,20 +62,20 @@ func ParseConfFile(path string) (conf *Conf, err error) {
|
||||||
d.Validator = multiconfig.MultiValidator(&multiconfig.RequiredValidator{})
|
d.Validator = multiconfig.MultiValidator(&multiconfig.RequiredValidator{})
|
||||||
if err = d.Load(conf); err != nil {
|
if err = d.Load(conf); err != nil {
|
||||||
slog.Error("parse stages conf", "error", err)
|
slog.Error("parse stages conf", "error", err)
|
||||||
return
|
return conf, err
|
||||||
}
|
}
|
||||||
if err = d.Validate(conf); err != nil {
|
if err = d.Validate(conf); err != nil {
|
||||||
slog.Error("validate stages conf", "error", err)
|
slog.Error("validate stages conf", "error", err)
|
||||||
return
|
return conf, err
|
||||||
}
|
}
|
||||||
return
|
return conf, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSHA256(filePath string) (hashStr string, err error) {
|
func GetSHA256(filePath string) (hashStr string, err error) {
|
||||||
// Open the file
|
// Open the file
|
||||||
file, err := os.Open(filePath)
|
file, err := os.Open(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return hashStr, err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if cerr := file.Close(); cerr != nil && err == nil {
|
if cerr := file.Close(); cerr != nil && err == nil {
|
||||||
|
|
@ -86,7 +86,7 @@ func GetSHA256(filePath string) (hashStr string, err error) {
|
||||||
// Calculate SHA-256
|
// Calculate SHA-256
|
||||||
hash := sha256.New()
|
hash := sha256.New()
|
||||||
if _, err = io.Copy(hash, file); err != nil {
|
if _, err = io.Copy(hash, file); err != nil {
|
||||||
return
|
return hashStr, err
|
||||||
}
|
}
|
||||||
hashStr = hex.EncodeToString(hash.Sum(nil))
|
hashStr = hex.EncodeToString(hash.Sum(nil))
|
||||||
return hashStr, nil
|
return hashStr, nil
|
||||||
|
|
@ -99,7 +99,7 @@ func parseMsg(confRoot, confName, msg, tag string) (
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
conventionalCommit, err = parseConventionalCommit(msg)
|
conventionalCommit, err = parseConventionalCommit(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return confPath, conventionalCommit, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
conventionalCommit = &ConventionalCommit{
|
conventionalCommit = &ConventionalCommit{
|
||||||
|
|
@ -112,13 +112,13 @@ func parseMsg(confRoot, confName, msg, tag string) (
|
||||||
confPath = filepath.Join(confRoot, conventionalCommit.Scope, confName)
|
confPath = filepath.Join(confRoot, conventionalCommit.Scope, confName)
|
||||||
relPath, err := filepath.Rel(confRoot, confPath)
|
relPath, err := filepath.Rel(confRoot, confPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return confPath, conventionalCommit, err
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(relPath, "..") || filepath.IsAbs(relPath) {
|
if strings.HasPrefix(relPath, "..") || filepath.IsAbs(relPath) {
|
||||||
err = fmt.Errorf("invalid scope as path: %s", conventionalCommit.Scope)
|
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) {
|
func hintValidScopes(confRoot, confName string) {
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ func generateStages(confStages []conf.ConfStage, groups []string) (
|
||||||
stages := []stage.Stage{}
|
stages := []stage.Stage{}
|
||||||
existNames := map[string]bool{}
|
existNames := map[string]bool{}
|
||||||
for i, s := range confStages {
|
for i, s := range confStages {
|
||||||
if s.Name == "" {
|
if len(groups) == 0 && (len(s.Groups) != 0 || s.Group != "") {
|
||||||
s.Name = fmt.Sprintf("stage-%d", i)
|
continue
|
||||||
}
|
}
|
||||||
ok := false
|
ok := false
|
||||||
if s.Group == "" && len(s.Groups) == 0 {
|
if s.Group == "" && len(s.Groups) == 0 {
|
||||||
|
|
@ -75,6 +75,9 @@ func generateStages(confStages []conf.ConfStage, groups []string) (
|
||||||
if !ok && len(groups) > 0 {
|
if !ok && len(groups) > 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if s.Name == "" {
|
||||||
|
s.Name = fmt.Sprintf("stage-%d", i)
|
||||||
|
}
|
||||||
_, ok = existNames[s.Name] // check for existence
|
_, ok = existNames[s.Name] // check for existence
|
||||||
if ok {
|
if ok {
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -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
|
// 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.
|
// more fields in the Result struct, don't mess everything up in Stderr.
|
||||||
err = fmt.Errorf("sample negative score: %d", conf.Score)
|
err = fmt.Errorf("sample negative score: %d", conf.Score)
|
||||||
return
|
return res, err
|
||||||
}
|
}
|
||||||
res.Score = conf.Score
|
res.Score = conf.Score
|
||||||
res.Comment = "sample comment"
|
res.Comment = "sample comment"
|
||||||
return
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user