From 72208487b0809e543c0765c2f10edc7660717b55 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Thu, 19 Sep 2024 10:03:17 +0800 Subject: [PATCH] feat: commitmsg parser --- cmd/joj3/conf.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 9ada30b..2bb892d 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -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 }