From 018bfbf8e570b84f6fc4803073ac88327195594c Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sun, 13 Oct 2024 05:12:59 -0400 Subject: [PATCH 1/2] fix(healthcheck): remove unused args --- cmd/repo-health-checker/main.go | 4 +--- pkg/healthcheck/forbidden.go | 11 +++-------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/cmd/repo-health-checker/main.go b/cmd/repo-health-checker/main.go index 5473a5c..be152f8 100644 --- a/cmd/repo-health-checker/main.go +++ b/cmd/repo-health-checker/main.go @@ -42,10 +42,8 @@ func main() { var gitWhitelist, metaFile []string showVersion := flag.Bool("version", false, "print current version") rootDir := flag.String("root", "", "") - repo := flag.String("repo", "", "") size := flag.Float64("repoSize", 2, "maximum size of the repo in MiB") localList := flag.String("localList", "", "") - droneBranch := flag.String("droneBranch", "", "") checkFileNameList := flag.String("checkFileNameList", "", "Comma-separated list of files to check.") checkFileSumList := flag.String("checkFileSumList", "", "Comma-separated list of expected checksums.") parseMultiValueFlag(&gitWhitelist, "whitelist", "") @@ -61,7 +59,7 @@ func main() { if err != nil { fmt.Printf("### Repo Size Check Failed:\n%s\n", err.Error()) } - err = healthcheck.ForbiddenCheck(*rootDir, gitWhitelist, *localList, *repo, *droneBranch) + err = healthcheck.ForbiddenCheck(*rootDir, gitWhitelist, *localList) if err != nil { fmt.Printf("### Forbidden File Check Failed:\n%s\n", err.Error()) } diff --git a/pkg/healthcheck/forbidden.go b/pkg/healthcheck/forbidden.go index 1a46c70..ed4f0da 100644 --- a/pkg/healthcheck/forbidden.go +++ b/pkg/healthcheck/forbidden.go @@ -70,7 +70,7 @@ func getForbiddens(root string, fileList []string, localList string) ([]string, // forbiddenCheck checks for forbidden files in the specified root directory. // It prints the list of forbidden files found, along with instructions on how to fix them. -func ForbiddenCheck(rootDir string, regexList []string, localList string, repo string, droneBranch string) error { +func ForbiddenCheck(rootDir string, regexList []string, localList string) error { forbids, err := getForbiddens(rootDir, regexList, localList) if err != nil { slog.Error("getting forbiddens", "error", err) @@ -78,13 +78,8 @@ func ForbiddenCheck(rootDir string, regexList []string, localList string, repo s } if len(forbids) > 0 { - return fmt.Errorf("The following forbidden files were found: %s\n\nTo fix it, first make a backup of your repository and then run the following commands:\nfor i in %s%s", - strings.Join(forbids, ", "), - strings.Join(forbids, " "), - fmt.Sprint( - "; do git filter-repo --force --invert-paths --path \"$i\"; done\ngit remote add origin ", - repo, "\ngit push --set-upstream origin ", - droneBranch, " --force")) + return fmt.Errorf("The following forbidden files were found: `%s`\n", + strings.Join(forbids, "`, `")) } return nil } -- 2.30.2 From f6e7ea73bd7e81273ba352a645b6b326f96ccd8c Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Mon, 14 Oct 2024 10:14:32 -0400 Subject: [PATCH 2/2] fix(healthcheck/forbidden): new hints --- pkg/healthcheck/forbidden.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/healthcheck/forbidden.go b/pkg/healthcheck/forbidden.go index ed4f0da..2c58ab9 100644 --- a/pkg/healthcheck/forbidden.go +++ b/pkg/healthcheck/forbidden.go @@ -78,8 +78,17 @@ func ForbiddenCheck(rootDir string, regexList []string, localList string) error } if len(forbids) > 0 { - return fmt.Errorf("The following forbidden files were found: `%s`\n", - strings.Join(forbids, "`, `")) + return fmt.Errorf("The following forbidden files were found: `%s`\n\n"+ + "To fix it, first make a backup of your repository and then run the following commands:\n"+ + "```bash\n"+ + "export GIT_BRANCH=$(git branch --show-current)\n"+ + "export GIT_REMOTE_URL=$(git config --get remote.origin.url)\n"+ + "for i in %s; do git filter-repo --force --invert-paths --path \"$i\"; done\n"+ + "git remote add origin $GIT_REMOTE_URL\n"+ + "git push --set-upstream origin $GIT_BRANCH --force\n"+ + "```\n", + strings.Join(forbids, "`, `"), + strings.Join(forbids, " ")) } return nil } -- 2.30.2