feat: using github.com/scornet256/go-logger
This commit is contained in:
parent
6f3224c9cc
commit
cf33cc31f4
10 changed files with 61 additions and 110 deletions
|
|
@ -2,10 +2,11 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"gogitlabber/cmd/gogitlabber/logging"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/scornet256/go-logger"
|
||||
)
|
||||
|
||||
// add a mutex to safely increment shared counters
|
||||
|
|
@ -38,7 +39,7 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
|||
repoDestination := repoDestinationPre + repoName
|
||||
|
||||
// log activity
|
||||
logging.Print("Starting on repository: "+repoName, nil)
|
||||
logger.Print("Starting on repository: "+repoName, nil)
|
||||
|
||||
// make gitlab url
|
||||
url := fmt.Sprintf("https://gitlab-token:%s@%s/%s.git", gitlabToken, gitlabHost, repoName)
|
||||
|
|
@ -47,7 +48,7 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
|||
checkRepo := func(repoDestination string) string {
|
||||
checkCmd := exec.Command("git", "-C", repoDestination, "remote", "-v")
|
||||
checkOutput, _ := checkCmd.CombinedOutput()
|
||||
logging.Print("Checking status for repository: "+repoName, nil)
|
||||
logger.Print("Checking status for repository: "+repoName, nil)
|
||||
|
||||
return string(checkOutput)
|
||||
}
|
||||
|
|
@ -59,19 +60,19 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
|||
case strings.Contains(string(repoStatus), "No such file or directory"):
|
||||
|
||||
// log activity
|
||||
logging.Print("Decided to clone repository: "+repoName, nil)
|
||||
logger.Print("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.Print("Cloning repository: "+repoName+" to "+repoDestination, nil)
|
||||
logger.Print("Cloning repository: "+repoName+" to "+repoDestination, nil)
|
||||
|
||||
return string(cloneOutput), err
|
||||
}
|
||||
_, err := cloneRepository(repoDestination, url)
|
||||
if err != nil {
|
||||
logging.Print("ERROR: %v\n", err)
|
||||
logger.Print("ERROR: %v\n", err)
|
||||
}
|
||||
|
||||
// set a lock, increment counters, update progressbar and unlock
|
||||
|
|
@ -88,7 +89,7 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
|||
|
||||
// pull the latest
|
||||
case strings.Contains(string(repoStatus), url):
|
||||
logging.Print("Decided to pull repository: "+repoName, nil)
|
||||
logger.Print("Decided to pull repository: "+repoName, nil)
|
||||
pullRepository(repoName, repoDestination)
|
||||
if !debug {
|
||||
descriptionPrefixPre := "Pulling repository "
|
||||
|
|
@ -98,8 +99,8 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
|||
}
|
||||
|
||||
default:
|
||||
logging.Print("ERROR: decided not to clone or pull repository: "+repoName, nil)
|
||||
logging.Print("ERROR: this is why: "+repoStatus, nil)
|
||||
logger.Print("ERROR: decided not to clone or pull repository: "+repoName, nil)
|
||||
logger.Print("ERROR: this is why: "+repoStatus, nil)
|
||||
|
||||
// set a lock, increment counters and unlock
|
||||
mu.Lock()
|
||||
|
|
@ -119,7 +120,7 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
|||
func pullRepository(repoName string, repoDestination string) {
|
||||
|
||||
// log activity
|
||||
logging.Print("Pulling repository: "+repoName+" at "+repoDestination, nil)
|
||||
logger.Print("Pulling repository: "+repoName+" at "+repoDestination, nil)
|
||||
|
||||
// find remote
|
||||
findRemote := func(repoDestination string) (string, error) {
|
||||
|
|
@ -129,9 +130,9 @@ func pullRepository(repoName string, repoDestination string) {
|
|||
return "", fmt.Errorf("finding remote: %v\n", err)
|
||||
}
|
||||
|
||||
logging.Print("Finding remote for repository: "+repoName+" at "+repoDestination, nil)
|
||||
logger.Print("Finding remote for repository: "+repoName+" at "+repoDestination, nil)
|
||||
remote := strings.Split(strings.TrimSpace(string(remoteOutput)), "\n")[0]
|
||||
logging.Print("Found remote; "+remote+" for repository: "+repoName+" at "+repoDestination, nil)
|
||||
logger.Print("Found remote; "+remote+" for repository: "+repoName+" at "+repoDestination, nil)
|
||||
return remote, nil
|
||||
}
|
||||
remote, _ := findRemote(repoDestination)
|
||||
|
|
@ -156,13 +157,13 @@ func pullRepository(repoName string, repoDestination string) {
|
|||
switch {
|
||||
case strings.Contains(string(pullOutput), "You have unstaged changes"):
|
||||
pullErrorMsg = append(pullErrorMsg, repoDestination)
|
||||
logging.Print("Found unstaged changes for repository: "+repoName+" at "+repoDestination, nil)
|
||||
logger.Print("Found unstaged changes for repository: "+repoName+" at "+repoDestination, nil)
|
||||
|
||||
default:
|
||||
logging.Print("ERROR: pulling "+repoName, nil)
|
||||
logger.Print("ERROR: pulling "+repoName, nil)
|
||||
}
|
||||
}
|
||||
|
||||
// log activity
|
||||
logging.Print("Pulled repository: "+repoName+" at "+repoDestination, nil)
|
||||
logger.Print("Pulled repository: "+repoName+" at "+repoDestination, nil)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue