From 4c15ac48d9b494863649bb6397460d8b47bb58fb Mon Sep 17 00:00:00 2001 From: BoYanZh Date: Thu, 29 May 2025 00:06:06 -0400 Subject: [PATCH] feat(healthcheck): support score --- cmd/repo-health-checker/main.go | 6 +----- internal/parser/healthcheck/meta.go | 1 + internal/parser/healthcheck/parser.go | 6 +++++- pkg/healthcheck/all.go | 3 +-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/repo-health-checker/main.go b/cmd/repo-health-checker/main.go index ba62e43..c4a16cd 100644 --- a/cmd/repo-health-checker/main.go +++ b/cmd/repo-health-checker/main.go @@ -9,9 +9,7 @@ import ( "fmt" "log/slog" "os" - "strings" - "github.com/joint-online-judge/JOJ3/cmd/joj3/env" "github.com/joint-online-judge/JOJ3/pkg/healthcheck" ) @@ -74,10 +72,8 @@ func main() { "checkFileSumList", checkFileSumList, "meta", metaFile, ) - groups := strings.Split(os.Getenv(env.Groups), ",") res := healthcheck.All( - rootDir, checkFileNameList, checkFileSumList, - groups, metaFile, repoSize, + rootDir, checkFileNameList, checkFileSumList, metaFile, repoSize, ) jsonRes, err := json.Marshal(res) if err != nil { diff --git a/internal/parser/healthcheck/meta.go b/internal/parser/healthcheck/meta.go index 9ca1a8f..39fd91a 100644 --- a/internal/parser/healthcheck/meta.go +++ b/internal/parser/healthcheck/meta.go @@ -9,6 +9,7 @@ var name = "healthcheck" type Healthcheck struct{} type Conf struct { + Score int `default:"0"` Stdout string `default:"stdout"` Stderr string `default:"stderr"` } diff --git a/internal/parser/healthcheck/parser.go b/internal/parser/healthcheck/parser.go index 464e06a..911c86a 100644 --- a/internal/parser/healthcheck/parser.go +++ b/internal/parser/healthcheck/parser.go @@ -34,10 +34,14 @@ func (*Healthcheck) parse(executorResult stage.ExecutorResult, conf Conf) (stage }, true } slog.Debug("healthcheck result", "res", res) + score := conf.Score + if res.Failed { + score = 0 + } comment := res.Msg forceQuit := res.Failed return stage.ParserResult{ - Score: 0, + Score: score, Comment: comment, }, forceQuit } diff --git a/pkg/healthcheck/all.go b/pkg/healthcheck/all.go index 3722072..4ad9a06 100644 --- a/pkg/healthcheck/all.go +++ b/pkg/healthcheck/all.go @@ -12,8 +12,7 @@ type Result struct { func All( rootDir, checkFileNameList, checkFileSumList string, - groups, metaFile []string, - repoSize float64, + metaFile []string, repoSize float64, ) (res Result) { var err error err = RepoSize(repoSize)