From dc6e5648323c5200ae4d433866a2369e518f2964 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sun, 16 Jun 2024 15:19:47 -0400 Subject: [PATCH] fix: output content --- cmd/healthcheck/main.go | 8 +++++--- pkg/healthcheck/forbidden.go | 16 +++++++--------- pkg/healthcheck/release.go | 12 ++---------- pkg/healthcheck/verify.go | 6 ++++-- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/cmd/healthcheck/main.go b/cmd/healthcheck/main.go index d10b311..03497dd 100644 --- a/cmd/healthcheck/main.go +++ b/cmd/healthcheck/main.go @@ -77,8 +77,10 @@ func main() { fmt.Printf("## Release Tag Check Failed:\n%s\n", err.Error()) } // FIXME: for drone usage - err = healthcheck.VerifyDirectory(*rootDir, *adminDir) - if err != nil { - fmt.Printf("## Directory File Check Failed:\n%s\n", err.Error()) + if adminDir != nil && *adminDir != "" { + err = healthcheck.VerifyDirectory(*rootDir, *adminDir) + if err != nil { + fmt.Printf("## Directory File Check Failed:\n%s\n", err.Error()) + } } } diff --git a/pkg/healthcheck/forbidden.go b/pkg/healthcheck/forbidden.go index 042767f..16549f8 100644 --- a/pkg/healthcheck/forbidden.go +++ b/pkg/healthcheck/forbidden.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "regexp" + "strings" ) // getForbiddens retrieves a list of forbidden files in the specified root directory. @@ -61,15 +62,12 @@ func ForbiddenCheck(rootDir string, regexList []string, repo string, droneBranch var message string if len(forbids) > 0 { - message += fmt.Sprint(103, "the following forbidden files were found: ") - for _, file := range forbids { - message += fmt.Sprint(file, ", ") - } - message += "\n\nTo fix it, first make a backup of your repository and then run the following commands:\nfor i in " - for _, file := range forbids { - message += fmt.Sprint(file, " ") - } - message += fmt.Sprint("; do git filter-repo --force --invert-paths --path \\\"\\$i\\\"; done\ngit remote add origin ", repo, "\ngit push --set-upstream origin ", droneBranch, " --force") + message = "The following forbidden files were found: " + + strings.Join(forbids, ", ") + + "\n\nTo fix it, first make a backup of your repository and then run the following commands:\nfor i in " + + 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(message) } return nil diff --git a/pkg/healthcheck/release.go b/pkg/healthcheck/release.go index 81beade..7bc1e85 100644 --- a/pkg/healthcheck/release.go +++ b/pkg/healthcheck/release.go @@ -2,19 +2,12 @@ package healthcheck import ( "fmt" + "strings" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" ) -func catTags(all []string) (out string) { - out = "" - for _, str := range all { - out += str + " " - } - return out -} - func getTagsFromRepo(repoPath string) ([]string, error) { repo, err := git.PlainOpen(repoPath) if err != nil { @@ -63,8 +56,7 @@ func CheckReleases(repoPath string, category string, n int) error { } } if !found { - tagList := catTags(tags) - return fmt.Errorf("Wrong release tag '%s'. Please use one of %s.", target, tagList) + return fmt.Errorf("Wrong release tag '%s'. Please use one of '%s'.", target, strings.Join(tags, "', '")) } return nil } diff --git a/pkg/healthcheck/verify.go b/pkg/healthcheck/verify.go index d1595ce..1549f0a 100644 --- a/pkg/healthcheck/verify.go +++ b/pkg/healthcheck/verify.go @@ -57,14 +57,16 @@ func VerifyDirectory(rootDir, compareDir string) error { relPath, _ := filepath.Rel(rootDir, path) file2 := filepath.Join(compareDir, relPath) if !fileExists(file2) { - return fmt.Errorf("File %s in %s is missing in %s. Please immediately revert your changes!\n", relPath, rootDir, compareDir) + return fmt.Errorf("File %s is missing. Please immediately revert your changes!\n", + filepath.Join(rootDir, relPath)) } match, err := filesMatch(path, file2) if err != nil { return fmt.Errorf("error matching files: %w", err) } if !match { - return fmt.Errorf("File %s in %s is not identical to %s. Please revert your changes or contact the teaching team if you have a valid reason for adjusting them.\n", relPath, rootDir, compareDir) + return fmt.Errorf("File %s is altered. Please revert your changes or contact the teaching team if you have a valid reason for adjusting them.\n", + filepath.Join(rootDir, relPath)) } } return nil