feat: improved logging when a repo gives an error

This commit is contained in:
Simon Cornet 2025-08-28 10:30:41 +02:00
commit acfc2b5485
2 changed files with 19 additions and 4 deletions

View file

@ -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)
}
}

View file

@ -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