From acfc2b5485b636f13031513e5aacd8a5819ec6c6 Mon Sep 17 00:00:00 2001 From: Simon Cornet Date: Thu, 28 Aug 2025 10:30:41 +0200 Subject: [PATCH] feat: improved logging when a repo gives an error --- cmd/gogitlabber/git.go | 5 +++-- cmd/gogitlabber/output.go | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cmd/gogitlabber/git.go b/cmd/gogitlabber/git.go index 16280a6..70194fd 100644 --- a/cmd/gogitlabber/git.go +++ b/cmd/gogitlabber/git.go @@ -26,6 +26,7 @@ type GitStats struct { errorCount int pullErrorMsgUnstaged []string pullErrorMsgUncommitted []string + generalErrors []string } // increment counters @@ -41,6 +42,7 @@ func (stats *GitStats) IncrementCounter(operation string, repoPath string) { stats.pulledCount++ case "error": stats.errorCount++ + stats.generalErrors = append(stats.generalErrors, repoPath) case "unstaged": stats.errorCount++ stats.pullErrorMsgUnstaged = append(stats.pullErrorMsgUnstaged, repoPath) @@ -263,7 +265,6 @@ func setGitUserEmail(repoName, repoDestination string) error { // manage results func handleResult(result GitOperationResult, stats *GitStats) { - switch result.Operation { case "cloned": stats.IncrementCounter("cloned", "") @@ -284,7 +285,7 @@ func handleResult(result GitOperationResult, stats *GitStats) { logger.Print("Found uncommitted changes in: "+result.RepoName, nil) default: - stats.IncrementCounter("error", "") + stats.IncrementCounter("error", result.RepoName) logger.Print("ERROR processing "+result.RepoName+": "+result.Error.Error(), nil) } } diff --git a/cmd/gogitlabber/output.go b/cmd/gogitlabber/output.go index 71f4c9a..26e2289 100644 --- a/cmd/gogitlabber/output.go +++ b/cmd/gogitlabber/output.go @@ -85,15 +85,29 @@ func printPullErrorUncommitted(stats *GitStats) { } } -// print errors +// print all errors func printAllErrors(stats *GitStats) { printPullErrorUnstaged(stats) printPullErrorUncommitted(stats) + printGeneralErrors(stats) +} + +// print general errors +func printGeneralErrors(stats *GitStats) { + if len(stats.generalErrors) > 0 { + fmt.Println("Repositories with errors:") + for _, repo := range stats.generalErrors { + fmt.Printf("❌ %s failed to process.\n", repo) + } + fmt.Println() + } } // check for errors func hasErrors(stats *GitStats) bool { - return len(stats.pullErrorMsgUnstaged) > 0 || len(stats.pullErrorMsgUncommitted) > 0 + return len(stats.pullErrorMsgUnstaged) > 0 || + len(stats.pullErrorMsgUncommitted) > 0 || + len(stats.generalErrors) > 0 // Add this } // print detailed summary