feat: added git user and mail config
This commit is contained in:
parent
241fe8c53b
commit
f24d204152
3 changed files with 40 additions and 6 deletions
|
|
@ -66,6 +66,11 @@ func checkoutRepositories(repositories []Repository) {
|
|||
cloneRepository := func(repoDestination string, url string) (string, error) {
|
||||
cloneCmd := exec.Command("git", "clone", url, repoDestination)
|
||||
cloneOutput, err := cloneCmd.CombinedOutput()
|
||||
|
||||
// set username and email
|
||||
setGitUserName(repoName, repoDestination)
|
||||
setGitUserMail(repoName, repoDestination)
|
||||
|
||||
logger.Print("Cloning repository: "+repoName+" to "+repoDestination, nil)
|
||||
|
||||
return string(cloneOutput), err
|
||||
|
|
@ -87,6 +92,11 @@ func checkoutRepositories(repositories []Repository) {
|
|||
case strings.Contains(string(repoStatus), url):
|
||||
logger.Print("Decided to pull repository: "+repoName, nil)
|
||||
pullRepository(repoName, repoDestination)
|
||||
|
||||
// set username and email
|
||||
setGitUserName(repoName, repoDestination)
|
||||
setGitUserMail(repoName, repoDestination)
|
||||
|
||||
if !config.Debug {
|
||||
_ = bar.Add(1)
|
||||
}
|
||||
|
|
@ -164,3 +174,23 @@ func pullRepository(repoName string, repoDestination string) {
|
|||
// log activity
|
||||
logger.Print("Pulled repository: "+repoName+" at "+repoDestination, nil)
|
||||
}
|
||||
|
||||
// function to set the git user name
|
||||
func setGitUserName(repoName string, repoDestination string) error {
|
||||
|
||||
gitUserNameCmd := exec.Command("git", "-C", repoDestination, "config", "user.name", config.GitUserName)
|
||||
_, err := gitUserNameCmd.CombinedOutput()
|
||||
|
||||
logger.Print("Setting git username for: "+repoName, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// function to set the git user mail
|
||||
func setGitUserMail(repoName string, repoDestination string) error {
|
||||
|
||||
gitUserMailCmd := exec.Command("git", "-C", repoDestination, "config", "user.mail", config.GitUserMail)
|
||||
_, err := gitUserMailCmd.CombinedOutput()
|
||||
|
||||
logger.Print("Setting git email for: "+repoName, nil)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ type Config struct {
|
|||
GitBackend string `yaml:"git_backend"`
|
||||
GitHost string `yaml:"git_host"`
|
||||
GitToken string `yaml:"git_token"`
|
||||
GitUserMail string `yaml:"git_user_mail"`
|
||||
GitUserName string `yaml:"git_user_name"`
|
||||
IncludeArchived string `yaml:"include_archived"`
|
||||
}
|
||||
|
||||
|
|
@ -30,6 +32,8 @@ func (conf *Config) setDefaults() {
|
|||
conf.GitBackend = ""
|
||||
conf.GitHost = "gitlab.com"
|
||||
conf.GitToken = ""
|
||||
conf.GitUserMail = ""
|
||||
conf.GitUserName = ""
|
||||
conf.IncludeArchived = "excluded"
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue