feat: commitmsg parser
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
zzjc1234 2024-09-19 10:03:17 +08:00
parent 175685c074
commit 72208487b0

View File

@ -2,6 +2,7 @@ package main
import (
"log/slog"
"strings"
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
"github.com/go-git/go-git/v5"
@ -84,7 +85,23 @@ func commitMsgToConf() (conf Conf, err error) {
}
msg := commit.Message
slog.Debug("commit msg to conf", "msg", msg)
// TODO: parse msg to conf name
conf, err = parseConfFile("conf.toml")
line := strings.Split(msg, "\n")[0]
words := strings.TrimSpace(line)
head := string(words[0])
file := "conf.toml"
if strings.HasSuffix(head, ":") || strings.HasSuffix(head, ".") {
head = head[:len(head)-1]
}
switch head {
case "feat", "fix", "refactor", "perf", "test", "build", "revert":
strings.Replace(file, "conf", "conf-cp", 1)
case "joj", "grading":
strings.Replace(file, "conf", "conf-oj", 1)
}
conf, err = parseConfFile(file)
return
}