From 901290d263660221616a4e5f9b9afa2a10b79da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E8=B5=B5=E5=98=89=E7=A8=8B521432910016?= Date: Sat, 12 Oct 2024 18:30:54 +0800 Subject: [PATCH] feat: check repo size with conf (#56) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: zzjc1234 <2359047351@qq.com> Co-authored-by: Boming Zhang Reviewed-on: https://focs.ji.sjtu.edu.cn/git/JOJ/JOJ3/pulls/56 Reviewed-by: 张泊明518370910136 Co-authored-by: 周赵嘉程521432910016 Co-committed-by: 周赵嘉程521432910016 --- cmd/repo-health-checker/main.go | 3 ++- pkg/healthcheck/reposize.go | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/repo-health-checker/main.go b/cmd/repo-health-checker/main.go index 160b587..65b90dd 100644 --- a/cmd/repo-health-checker/main.go +++ b/cmd/repo-health-checker/main.go @@ -44,6 +44,7 @@ func main() { checkRelease := flag.Bool("checkRelease", true, "trigger release check") rootDir := flag.String("root", "", "") repo := flag.String("repo", "", "") + size := flag.Float64("reposize", 2, "size of the repo") localList := flag.String("localList", "", "") droneBranch := flag.String("droneBranch", "", "") checkFileNameList := flag.String("checkFileNameList", "", "Comma-separated list of files to check.") @@ -57,7 +58,7 @@ func main() { } setupSlog() var err error - err = healthcheck.RepoSize() + err = healthcheck.RepoSize(*size) if err != nil { fmt.Printf("### Repo Size Check Failed:\n%s\n", err.Error()) } diff --git a/pkg/healthcheck/reposize.go b/pkg/healthcheck/reposize.go index dd17d06..939adb8 100644 --- a/pkg/healthcheck/reposize.go +++ b/pkg/healthcheck/reposize.go @@ -10,7 +10,7 @@ import ( // RepoSize checks the size of the repository to determine if it is oversized. // It executes the 'git count-objects -v' command to obtain the size information, -func RepoSize() error { +func RepoSize(confSize float64) error { // TODO: reimplement here when go-git is available // https://github.com/go-git/go-git/blob/master/COMPATIBILITY.md cmd := exec.Command("git", "count-objects", "-v") @@ -33,8 +33,8 @@ func RepoSize() error { sum += size } } - if sum > 2048 { - return fmt.Errorf("Repository larger than 2MB. Please clean up or contact the teaching team.") + if sum > int(confSize*1024) { + return fmt.Errorf("Repository larger than %.1f MiB. Please clean up or contact the teaching team.", confSize) } return nil }