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) {
|
cloneRepository := func(repoDestination string, url string) (string, error) {
|
||||||
cloneCmd := exec.Command("git", "clone", url, repoDestination)
|
cloneCmd := exec.Command("git", "clone", url, repoDestination)
|
||||||
cloneOutput, err := cloneCmd.CombinedOutput()
|
cloneOutput, err := cloneCmd.CombinedOutput()
|
||||||
|
|
||||||
|
// set username and email
|
||||||
|
setGitUserName(repoName, repoDestination)
|
||||||
|
setGitUserMail(repoName, repoDestination)
|
||||||
|
|
||||||
logger.Print("Cloning repository: "+repoName+" to "+repoDestination, nil)
|
logger.Print("Cloning repository: "+repoName+" to "+repoDestination, nil)
|
||||||
|
|
||||||
return string(cloneOutput), err
|
return string(cloneOutput), err
|
||||||
|
|
@ -87,6 +92,11 @@ func checkoutRepositories(repositories []Repository) {
|
||||||
case strings.Contains(string(repoStatus), url):
|
case strings.Contains(string(repoStatus), url):
|
||||||
logger.Print("Decided to pull repository: "+repoName, nil)
|
logger.Print("Decided to pull repository: "+repoName, nil)
|
||||||
pullRepository(repoName, repoDestination)
|
pullRepository(repoName, repoDestination)
|
||||||
|
|
||||||
|
// set username and email
|
||||||
|
setGitUserName(repoName, repoDestination)
|
||||||
|
setGitUserMail(repoName, repoDestination)
|
||||||
|
|
||||||
if !config.Debug {
|
if !config.Debug {
|
||||||
_ = bar.Add(1)
|
_ = bar.Add(1)
|
||||||
}
|
}
|
||||||
|
|
@ -164,3 +174,23 @@ func pullRepository(repoName string, repoDestination string) {
|
||||||
// log activity
|
// log activity
|
||||||
logger.Print("Pulled repository: "+repoName+" at "+repoDestination, nil)
|
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"`
|
GitBackend string `yaml:"git_backend"`
|
||||||
GitHost string `yaml:"git_host"`
|
GitHost string `yaml:"git_host"`
|
||||||
GitToken string `yaml:"git_token"`
|
GitToken string `yaml:"git_token"`
|
||||||
|
GitUserMail string `yaml:"git_user_mail"`
|
||||||
|
GitUserName string `yaml:"git_user_name"`
|
||||||
IncludeArchived string `yaml:"include_archived"`
|
IncludeArchived string `yaml:"include_archived"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,6 +32,8 @@ func (conf *Config) setDefaults() {
|
||||||
conf.GitBackend = ""
|
conf.GitBackend = ""
|
||||||
conf.GitHost = "gitlab.com"
|
conf.GitHost = "gitlab.com"
|
||||||
conf.GitToken = ""
|
conf.GitToken = ""
|
||||||
|
conf.GitUserMail = ""
|
||||||
|
conf.GitUserName = ""
|
||||||
conf.IncludeArchived = "excluded"
|
conf.IncludeArchived = "excluded"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
14
readme.md
14
readme.md
|
|
@ -29,23 +29,23 @@ GitLab:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# ~/.config/gogitlabber/gitlab.example.com.yaml
|
# ~/.config/gogitlabber/gitlab.example.com.yaml
|
||||||
debug: false
|
|
||||||
concurrency: 15
|
concurrency: 15
|
||||||
git_host: "gitlab.example.net"
|
debug: false
|
||||||
git_token: "glpat-"
|
|
||||||
git_backend: "gitlab"
|
|
||||||
include_archived: "excluded"
|
|
||||||
destination: "$HOME/Documents"
|
destination: "$HOME/Documents"
|
||||||
|
git_backend: "gitlab"
|
||||||
|
git_host: "gitlab.example.com"
|
||||||
|
git_token: "glpat-"
|
||||||
|
git_user_mail: "john.doe@example.com"
|
||||||
|
git_user_name: "John Doe"
|
||||||
|
include_archived: "excluded"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
gogitlabber -config=~/.config/gogitlabber/gitlab.example.com.yaml
|
gogitlabber -config=~/.config/gogitlabber/gitlab.example.com.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Access Token Permissions
|
## Access Token Permissions
|
||||||
|
|
||||||
### Gitea
|
### Gitea
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue