style: use linter to style the code
This commit is contained in:
parent
f1c372a5cc
commit
0243f631fb
4 changed files with 21 additions and 22 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
|
||||||
|
|
@ -59,20 +59,20 @@ func checkoutRepositories(repositories []Repository) {
|
||||||
|
|
||||||
for _, repo := range repositories {
|
for _, repo := range repositories {
|
||||||
|
|
||||||
// create clone gitlab url
|
// create clone gitlab url
|
||||||
repoName := string(repo.PathWithNamespace)
|
repoName := string(repo.PathWithNamespace)
|
||||||
gitlabUrl := fmt.Sprintf("https://gitlab-token:%s@%s/%s.git",
|
gitlabUrl := fmt.Sprintf("https://gitlab-token:%s@%s/%s.git",
|
||||||
gitlabToken, gitlabHost, repoName)
|
gitlabToken, gitlabHost, repoName)
|
||||||
|
|
||||||
// create repository destination
|
// create repository destination
|
||||||
repoDestination := repoDestinationPre + repoName
|
repoDestination := repoDestinationPre + repoName
|
||||||
|
|
||||||
// create bar description
|
// create bar description
|
||||||
descriptionPrefixPre := "Cloning repository "
|
descriptionPrefixPre := "Cloning repository "
|
||||||
descriptionPrefix := descriptionPrefixPre + repoName + " ..."
|
descriptionPrefix := descriptionPrefixPre + repoName + " ..."
|
||||||
bar.Describe(descriptionPrefix)
|
bar.Describe(descriptionPrefix)
|
||||||
|
|
||||||
// clone the repo
|
// clone the repo
|
||||||
cloneOutput, err := cloneRepository(repoDestination, gitlabUrl)
|
cloneOutput, err := cloneRepository(repoDestination, gitlabUrl)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -94,15 +94,15 @@ func checkoutRepositories(repositories []Repository) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case cloning failed and the directory does not exist
|
// in case cloning failed and the directory does not exist
|
||||||
// print the clone error and continue
|
// print the clone error and continue
|
||||||
log.Printf("\n❌ error cloning %s: %v\n%s\n", repoName, err, cloneOutput)
|
log.Printf("\n❌ error cloning %s: %v\n%s\n", repoName, err, cloneOutput)
|
||||||
errorCount = errorCount + 1
|
errorCount = errorCount + 1
|
||||||
bar.Add(1)
|
bar.Add(1)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// finish the clone
|
// finish the clone
|
||||||
clonedCount = clonedCount + 1
|
clonedCount = clonedCount + 1
|
||||||
bar.Add(1)
|
bar.Add(1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,9 @@ import (
|
||||||
|
|
||||||
func manageArguments() {
|
func manageArguments() {
|
||||||
|
|
||||||
// configuration vars
|
// configuration vars
|
||||||
var archivedFlag = flag.String("archived", "excluded", "to include archived repositories (any|excluded|exclusive)\nenv = GOGITLABBER_ARCHIVED\n")
|
var archivedFlag = flag.String("archived", "excluded", "to include archived repositories (any|excluded|exclusive)\nenv = GOGITLABBER_ARCHIVED\n")
|
||||||
var destinationFlag = flag.String("destination", "", "specify where to check the repositories out\n example: -destination=$HOME/repos\nenv = GOGITLABBER_DESTINATION\n")
|
var destinationFlag = flag.String("destination", "", "specify where to check the repositories out\n example: -destination=$HOME/repos\nenv = GOGITLABBER_DESTINATION\n")
|
||||||
var hostFlag = flag.String("gitlab-url", "", "specify gitlab host\n example: -gitlab-url=gitlab.example.com\nenv = GITLAB_URL\n")
|
var hostFlag = flag.String("gitlab-url", "", "specify gitlab host\n example: -gitlab-url=gitlab.example.com\nenv = GITLAB_URL\n")
|
||||||
var tokenFlag = flag.String("gitlab-api-token", "", "specify gitlab api token\n example: -gitlab-api=glpat-xxxx\nenv = GITLAB_API_TOKEN\n")
|
var tokenFlag = flag.String("gitlab-api-token", "", "specify gitlab api token\n example: -gitlab-api=glpat-xxxx\nenv = GITLAB_API_TOKEN\n")
|
||||||
|
|
||||||
|
|
@ -32,15 +32,15 @@ func manageArguments() {
|
||||||
gitlabToken = envToken
|
gitlabToken = envToken
|
||||||
}
|
}
|
||||||
|
|
||||||
if envRepoDest := os.Getenv("GOGITLABBER_DESTINATION"); envRepoDest != "" {
|
if envRepoDest := os.Getenv("GOGITLABBER_DESTINATION"); envRepoDest != "" {
|
||||||
repoDestinationPre = envRepoDest
|
repoDestinationPre = envRepoDest
|
||||||
}
|
}
|
||||||
|
|
||||||
if envArchived := os.Getenv("GOGITLABBER_ARCHIVED"); envArchived != "" {
|
if envArchived := os.Getenv("GOGITLABBER_ARCHIVED"); envArchived != "" {
|
||||||
includeArchived = envArchived
|
includeArchived = envArchived
|
||||||
}
|
}
|
||||||
|
|
||||||
// fail if no configuration found
|
// fail if no configuration found
|
||||||
if gitlabHost == "" {
|
if gitlabHost == "" {
|
||||||
fmt.Println("Fatal: No GitLab Host found.")
|
fmt.Println("Fatal: No GitLab Host found.")
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ var gitlabHost string
|
||||||
|
|
||||||
var clonedCount int
|
var clonedCount int
|
||||||
var errorCount int
|
var errorCount int
|
||||||
var pulledCount int
|
var pulledCount int
|
||||||
var pullError int
|
var pullError int
|
||||||
var pullErrorMsg []string
|
var pullErrorMsg []string
|
||||||
|
|
||||||
|
|
@ -33,8 +33,8 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// manage found repositories
|
// manage found repositories
|
||||||
progressBar(repositories)
|
progressBar(repositories)
|
||||||
checkoutRepositories(repositories)
|
checkoutRepositories(repositories)
|
||||||
printSummary()
|
printSummary()
|
||||||
printPullError(pullErrorMsg)
|
printPullError(pullErrorMsg)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue