From e32fb792f679f34679d17bc501b078d778f1bd0e Mon Sep 17 00:00:00 2001 From: Simon Cornet Date: Thu, 6 Mar 2025 08:49:31 +0100 Subject: [PATCH] [logging] feat: simplified the names --- cmd/gogitlabber/git.go | 28 ++++++++++++++-------------- cmd/gogitlabber/gitlab.go | 12 ++++++------ cmd/gogitlabber/input.go | 20 ++++++++++---------- cmd/gogitlabber/logging/logging.go | 4 ++-- cmd/gogitlabber/main.go | 6 +++--- cmd/gogitlabber/output.go | 6 +++--- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/cmd/gogitlabber/git.go b/cmd/gogitlabber/git.go index 8fbb00b..c0d4a9f 100644 --- a/cmd/gogitlabber/git.go +++ b/cmd/gogitlabber/git.go @@ -38,7 +38,7 @@ func checkoutRepositories(repositories []Repository, concurrency int) { repoDestination := repoDestinationPre + repoName // log activity - logging.LogPrint(debug, "Starting on repository: "+repoName, nil) + logging.Print(debug, "Starting on repository: "+repoName, nil) // make gitlab url url := fmt.Sprintf("https://gitlab-token:%s@%s/%s.git", gitlabToken, gitlabHost, repoName) @@ -47,7 +47,7 @@ func checkoutRepositories(repositories []Repository, concurrency int) { checkRepo := func(repoDestination string) string { checkCmd := exec.Command("git", "-C", repoDestination, "remote", "-v") checkOutput, _ := checkCmd.CombinedOutput() - logging.LogPrint(debug, "Checking status for repository: "+repoName, nil) + logging.Print(debug, "Checking status for repository: "+repoName, nil) return string(checkOutput) } @@ -59,19 +59,19 @@ func checkoutRepositories(repositories []Repository, concurrency int) { case strings.Contains(string(repoStatus), "No such file or directory"): // log activity - logging.LogPrint(debug, "Decided to clone repository: "+repoName, nil) + logging.Print(debug, "Decided to clone repository: "+repoName, nil) // clone the repo cloneRepository := func(repoDestination string, url string) (string, error) { cloneCmd := exec.Command("git", "clone", url, repoDestination) cloneOutput, err := cloneCmd.CombinedOutput() - logging.LogPrint(debug, "Cloning repository: "+repoName+" to "+repoDestination, nil) + logging.Print(debug, "Cloning repository: "+repoName+" to "+repoDestination, nil) return string(cloneOutput), err } _, err := cloneRepository(repoDestination, url) if err != nil { - logging.LogPrint(debug, "ERROR: %v\n", err) + logging.Print(debug, "ERROR: %v\n", err) } // set a lock, increment counters, update progressbar and unlock @@ -88,7 +88,7 @@ func checkoutRepositories(repositories []Repository, concurrency int) { // pull the latest case strings.Contains(string(repoStatus), url): - logging.LogPrint(debug, "Decided to pull repository: "+repoName, nil) + logging.Print(debug, "Decided to pull repository: "+repoName, nil) pullRepository(repoName, repoDestination) if !debug { descriptionPrefixPre := "Pulling repository " @@ -98,8 +98,8 @@ func checkoutRepositories(repositories []Repository, concurrency int) { } default: - logging.LogPrint(debug, "ERROR: decided not to clone or pull repository: "+repoName, nil) - logging.LogPrint(debug, "ERROR: this is why: "+repoStatus, nil) + logging.Print(debug, "ERROR: decided not to clone or pull repository: "+repoName, nil) + logging.Print(debug, "ERROR: this is why: "+repoStatus, nil) // set a lock, increment counters and unlock mu.Lock() @@ -119,7 +119,7 @@ func checkoutRepositories(repositories []Repository, concurrency int) { func pullRepository(repoName string, repoDestination string) { // log activity - logging.LogPrint(debug, "Pulling repository: "+repoName+" at "+repoDestination, nil) + logging.Print(debug, "Pulling repository: "+repoName+" at "+repoDestination, nil) // find remote findRemote := func(repoDestination string) (string, error) { @@ -129,9 +129,9 @@ func pullRepository(repoName string, repoDestination string) { return "", fmt.Errorf("finding remote: %v\n", err) } - logging.LogPrint(debug, "Finding remote for repository: "+repoName+" at "+repoDestination, nil) + logging.Print(debug, "Finding remote for repository: "+repoName+" at "+repoDestination, nil) remote := strings.Split(strings.TrimSpace(string(remoteOutput)), "\n")[0] - logging.LogPrint(debug, "Found remote; "+remote+" for repository: "+repoName+" at "+repoDestination, nil) + logging.Print(debug, "Found remote; "+remote+" for repository: "+repoName+" at "+repoDestination, nil) return remote, nil } remote, _ := findRemote(repoDestination) @@ -156,13 +156,13 @@ func pullRepository(repoName string, repoDestination string) { switch { case strings.Contains(string(pullOutput), "You have unstaged changes"): pullErrorMsg = append(pullErrorMsg, repoDestination) - logging.LogPrint(debug, "Found unstaged changes for repository: "+repoName+" at "+repoDestination, nil) + logging.Print(debug, "Found unstaged changes for repository: "+repoName+" at "+repoDestination, nil) default: - logging.LogPrint(debug, "ERROR: pulling "+repoName, nil) + logging.Print(debug, "ERROR: pulling "+repoName, nil) } } // log activity - logging.LogPrint(debug, "Pulled repository: "+repoName+" at "+repoDestination, nil) + logging.Print(debug, "Pulled repository: "+repoName+" at "+repoDestination, nil) } diff --git a/cmd/gogitlabber/gitlab.go b/cmd/gogitlabber/gitlab.go index c3d9d51..25db451 100644 --- a/cmd/gogitlabber/gitlab.go +++ b/cmd/gogitlabber/gitlab.go @@ -28,16 +28,16 @@ func fetchRepositoriesGitlab() ([]Repository, error) { url := fmt.Sprintf("https://%s/api/v4/projects?%s&%s&%s%s", gitlabHost, membership, order, perpage, archived) - logging.LogPrint(debug, "HTTP: Creating API request", nil) + logging.Print(debug, "HTTP: Creating API request", nil) req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("ERROR: creating request: %v\n", err) } - logging.LogPrint(debug, "HTTP: Adding PRIVATE-TOKEN header to API request", nil) + logging.Print(debug, "HTTP: Adding PRIVATE-TOKEN header to API request", nil) req.Header.Set("PRIVATE-TOKEN", gitlabToken) - logging.LogPrint(debug, "HTTP: Making request", nil) + logging.Print(debug, "HTTP: Making request", nil) client := &http.Client{} resp, err := client.Do(req) if err != nil { @@ -49,7 +49,7 @@ func fetchRepositoriesGitlab() ([]Repository, error) { return nil, fmt.Errorf("ERROR: API request failed with status: %d\n", resp.StatusCode) } - logging.LogPrint(debug, "HTTP: Decoding JSON response", nil) + logging.Print(debug, "HTTP: Decoding JSON response", nil) var repositories []Repository if err := json.NewDecoder(resp.Body).Decode(&repositories); err != nil { return nil, fmt.Errorf("ERROR: decoding response: %v\n", err) @@ -62,10 +62,10 @@ func fetchRepositoriesGitlab() ([]Repository, error) { repoCount := len(repositories) err = bar.Set(0) if err != nil { - logging.LogFatal("Could not reset the progressbar", err) + logging.Fatal("Could not reset the progressbar", err) } bar.ChangeMax(repoCount) - logging.LogPrint(debug, "HTTP: Returning repositories found", nil) + logging.Print(debug, "HTTP: Returning repositories found", nil) return repositories, nil } diff --git a/cmd/gogitlabber/input.go b/cmd/gogitlabber/input.go index 465de00..900c603 100644 --- a/cmd/gogitlabber/input.go +++ b/cmd/gogitlabber/input.go @@ -24,7 +24,7 @@ func setDefaultsFromEnv() { if debugVal, err := strconv.ParseBool(envDebug); err == nil { debug = debugVal } else { - logging.LogPrint(debug, "Warning: Invalid debug value in environment, using default", nil) + logging.Print(debug, "Warning: Invalid debug value in environment, using default", nil) } } @@ -44,7 +44,7 @@ func setDefaultsFromEnv() { if concurrencyVal, err := strconv.Atoi(envConcurrency); err == nil { concurrency = concurrencyVal } else { - logging.LogPrint(debug, "Warning: Invalid concurrency value in environment, using default", nil) + logging.Print(debug, "Warning: Invalid concurrency value in environment, using default", nil) } } @@ -53,7 +53,7 @@ func setDefaultsFromEnv() { case "any", "exclusive", "excluded": includeArchived = envArchived default: - logging.LogPrint(debug, "Warning: Invalid archived value in environment, using default", nil) + logging.Print(debug, "Warning: Invalid archived value in environment, using default", nil) } } } @@ -112,7 +112,7 @@ func manageArguments() { // validate required parameters if gitlabToken == "" { flag.Usage() - logging.LogFatal("Configuration: Gitlab API Token not found", nil) + logging.Fatal("Configuration: Gitlab API Token not found", nil) } // validate archived option @@ -120,15 +120,15 @@ func manageArguments() { case "any", "exclusive", "excluded": default: flag.Usage() - logging.LogFatal("Configuration: Invalid archive option: "+includeArchived, nil) + logging.Fatal("Configuration: Invalid archive option: "+includeArchived, nil) } // log configuration - logging.LogPrint(debug, "Configuration: Using GitLab host: "+gitlabHost, nil) - logging.LogPrint(debug, "Configuration: Using destination: "+repoDestinationPre, nil) - logging.LogPrint(debug, "Configuration: Using concurrency: "+strconv.Itoa(concurrency), nil) - logging.LogPrint(debug, "Configuration: Using archived option: "+includeArchived, nil) + logging.Print(debug, "Configuration: Using GitLab host: "+gitlabHost, nil) + logging.Print(debug, "Configuration: Using destination: "+repoDestinationPre, nil) + logging.Print(debug, "Configuration: Using concurrency: "+strconv.Itoa(concurrency), nil) + logging.Print(debug, "Configuration: Using archived option: "+includeArchived, nil) if debug { - logging.LogPrint(debug, "Configuration: Debug mode enabled", nil) + logging.Print(debug, "Configuration: Debug mode enabled", nil) } } diff --git a/cmd/gogitlabber/logging/logging.go b/cmd/gogitlabber/logging/logging.go index 5732540..83b18d6 100644 --- a/cmd/gogitlabber/logging/logging.go +++ b/cmd/gogitlabber/logging/logging.go @@ -4,7 +4,7 @@ import ( "log" ) -func LogPrint(debug bool, message string, err error) { +func Print(debug bool, message string, err error) { if debug { if err != nil { log.Printf("gogitlabber | DEBUG: %v error: %v\n", message, err) @@ -15,7 +15,7 @@ func LogPrint(debug bool, message string, err error) { } } -func LogFatal(message string, err error) { +func Fatal(message string, err error) { if err != nil { log.Fatalf("gogitlabber | FATAL: %v error: %v\n", message, err) } diff --git a/cmd/gogitlabber/main.go b/cmd/gogitlabber/main.go index fa7788f..0082486 100644 --- a/cmd/gogitlabber/main.go +++ b/cmd/gogitlabber/main.go @@ -34,9 +34,9 @@ func main() { // check for git err := verifyGitAvailable() if err != nil { - logging.LogFatal("git not found in path: %v", err) + logging.Fatal("git not found in path: %v", err) } - logging.LogPrint(debug, "VALIDATION: git found in path", nil) + logging.Print(debug, "VALIDATION: git found in path", nil) // make initial progressbar if !debug { @@ -47,7 +47,7 @@ func main() { // fetch repository information from gitlab repositories, err := fetchRepositoriesGitlab() if err != nil { - logging.LogFatal("FATAL: %v", err) + logging.Fatal("FATAL: %v", err) } // manage found repositories diff --git a/cmd/gogitlabber/output.go b/cmd/gogitlabber/output.go index 4ac67e7..461fc34 100644 --- a/cmd/gogitlabber/output.go +++ b/cmd/gogitlabber/output.go @@ -32,17 +32,17 @@ func progressBar() { ) // initialize progressbar - logging.LogPrint(debug, "Initialize progressbar", nil) + logging.Print(debug, "Initialize progressbar", nil) err := bar.RenderBlank() progressBarAdd(1) if err != nil { - logging.LogFatal("Initialization of the progressbar failed", err) + logging.Fatal("Initialization of the progressbar failed", err) } } func progressBarAdd(amount int) { if err := bar.Add(amount); err != nil { - logging.LogPrint(debug, "ERROR: Progress bar update error: %v\n", err) + logging.Print(debug, "ERROR: Progress bar update error: %v\n", err) } }