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 errorCount int
pullErrorMsgUnstaged []string pullErrorMsgUnstaged []string
pullErrorMsgUncommitted []string pullErrorMsgUncommitted []string
generalErrors []string
} }
// increment counters // increment counters
@ -41,6 +42,7 @@ func (stats *GitStats) IncrementCounter(operation string, repoPath string) {
stats.pulledCount++ stats.pulledCount++
case "error": case "error":
stats.errorCount++ stats.errorCount++
stats.generalErrors = append(stats.generalErrors, repoPath)
case "unstaged": case "unstaged":
stats.errorCount++ stats.errorCount++
stats.pullErrorMsgUnstaged = append(stats.pullErrorMsgUnstaged, repoPath) stats.pullErrorMsgUnstaged = append(stats.pullErrorMsgUnstaged, repoPath)
@ -263,7 +265,6 @@ func setGitUserEmail(repoName, repoDestination string) error {
// manage results // manage results
func handleResult(result GitOperationResult, stats *GitStats) { func handleResult(result GitOperationResult, stats *GitStats) {
switch result.Operation { switch result.Operation {
case "cloned": case "cloned":
stats.IncrementCounter("cloned", "") stats.IncrementCounter("cloned", "")
@ -284,7 +285,7 @@ func handleResult(result GitOperationResult, stats *GitStats) {
logger.Print("Found uncommitted changes in: "+result.RepoName, nil) logger.Print("Found uncommitted changes in: "+result.RepoName, nil)
default: default:
stats.IncrementCounter("error", "") stats.IncrementCounter("error", result.RepoName)
logger.Print("ERROR processing "+result.RepoName+": "+result.Error.Error(), nil) 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) { func printAllErrors(stats *GitStats) {
printPullErrorUnstaged(stats) printPullErrorUnstaged(stats)
printPullErrorUncommitted(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 // check for errors
func hasErrors(stats *GitStats) bool { 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 // print detailed summary