style: moved functions out of global namespace

This commit is contained in:
Simon Cornet 2025-02-28 09:21:07 +01:00
commit f8c85ca0d3

View file

@ -23,8 +23,15 @@ func checkoutRepositories(repositories []Repository) {
bar.Describe(descriptionPrefix) bar.Describe(descriptionPrefix)
// clone the repo // clone the repo
cloneRepository := func(repoDestination string, gitlabUrl string) (string, error) {
cloneCmd := exec.Command("git", "clone", gitlabUrl, repoDestination)
cloneOutput, err := cloneCmd.CombinedOutput()
return string(cloneOutput), err
}
cloneOutput, err := cloneRepository(repoDestination, url) cloneOutput, err := cloneRepository(repoDestination, url)
// try to pull if clone didnt work
if err != nil { if err != nil {
// if repo already exists, try to pull the latest changes // if repo already exists, try to pull the latest changes
@ -35,7 +42,7 @@ func checkoutRepositories(repositories []Repository) {
descriptionPrefix := descriptionPrefixPre + repoName + " ..." descriptionPrefix := descriptionPrefixPre + repoName + " ..."
bar.Describe(descriptionPrefix) bar.Describe(descriptionPrefix)
pullRepositories(repoDestination) pullRepository(repoDestination)
pulledCount = pulledCount + 1 pulledCount = pulledCount + 1
continue continue
} }
@ -54,14 +61,10 @@ func checkoutRepositories(repositories []Repository) {
} }
} }
func cloneRepository(repoDestination string, gitlabUrl string) (string, error) { func pullRepository(repoDestination string) (string, error) {
cloneCmd := exec.Command("git", "clone", gitlabUrl, repoDestination)
cloneOutput, err := cloneCmd.CombinedOutput()
return string(cloneOutput), err // find remote
} findRemote := func(repoDestination string) (string, error) {
func findRemote(repoDestination string) (string, error) {
remoteCmd := exec.Command("git", "-C", repoDestination, "remote", "show") remoteCmd := exec.Command("git", "-C", repoDestination, "remote", "show")
remoteOutput, err := remoteCmd.CombinedOutput() remoteOutput, err := remoteCmd.CombinedOutput()
if err != nil { if err != nil {
@ -70,10 +73,10 @@ func findRemote(repoDestination string) (string, error) {
remote := strings.Split(strings.TrimSpace(string(remoteOutput)), "\n")[0] remote := strings.Split(strings.TrimSpace(string(remoteOutput)), "\n")[0]
return remote, nil return remote, nil
} }
remote, _ := findRemote(repoDestination)
func pullRepositories(repoDestination string) (string, error) { // pull repository
remote, err := findRemote(repoDestination)
pullCmd := exec.Command("git", "-C", repoDestination, "pull", remote) pullCmd := exec.Command("git", "-C", repoDestination, "pull", remote)
pullOutput, err := pullCmd.CombinedOutput() pullOutput, err := pullCmd.CombinedOutput()