From 64b557043457f63d5fe90a20de66d8fb4f5de6a4 Mon Sep 17 00:00:00 2001 From: Andreas Wachter Date: Thu, 2 Dec 2021 18:43:39 +0100 Subject: [PATCH 1/2] added function to exclude repos --- .github/workflows/go.yml | 19 +++++++------------ .gitignore | 3 ++- main.go | 38 ++++++++++++++++++++++++++++++++++++++ types.go | 15 ++++++++------- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 2f7f3bb..c573af9 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -20,19 +20,8 @@ jobs: with: go-version: 1.17 - - name: Build - run: go build -v ./... - - name: Test run: go test -v ./... - - - name: Upload a Build Artifact - uses: actions/upload-artifact@v2.2.3 - with: - # Artifact name - name: gickup - # A file, directory or wildcard pattern that describes what to upload - path: gickup - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 @@ -42,4 +31,10 @@ jobs: version: latest args: release --rm-dist env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload a Build Artifact + uses: actions/upload-artifact@v2 + with: + name: gickup + path: dist/* \ No newline at end of file diff --git a/.gitignore b/.gitignore index 657a922..680d3d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bla.conf -gickup \ No newline at end of file +gickup +conf.yml \ No newline at end of file diff --git a/main.go b/main.go index ba57707..24263e0 100644 --- a/main.go +++ b/main.go @@ -55,6 +55,14 @@ func ReadConfigfile(configfile string) *Conf { return &t } +func GetExcludedMap(excludes []string) map[string]bool { + excludemap := make(map[string]bool) + for _, exclude := range excludes { + excludemap[exclude] = true + } + return excludemap +} + func Locally(repo Repo, l Local) { if _, err := os.Stat(l.Path); os.IsNotExist(err) { err := os.MkdirAll(l.Path, 0777) @@ -288,7 +296,12 @@ func getGithub(conf *Conf) []Repo { i++ } + exclude := GetExcludedMap(repo.Exclude) + for _, r := range githubrepos { + if exclude[*r.Name] { + continue + } repos = append(repos, Repo{Name: r.GetName(), Url: r.GetCloneURL(), SshUrl: r.GetSSHURL(), Token: repo.Token, Defaultbranch: r.GetDefaultBranch(), Origin: repo}) } } @@ -326,7 +339,12 @@ func getGitea(conf *Conf) []Repo { i++ } + exclude := GetExcludedMap(repo.Exclude) + for _, r := range gitearepos { + if exclude[r.Name] { + continue + } repos = append(repos, Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo}) } } @@ -343,7 +361,12 @@ func getGogs(conf *Conf) []Repo { log.Panic().Str("stage", "gogs").Str("url", repo.Url).Msg(err.Error()) } + exclude := GetExcludedMap(repo.Exclude) + for _, r := range gogsrepos { + if exclude[r.Name] { + continue + } repos = append(repos, Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo}) } } @@ -387,7 +410,13 @@ func getGitlab(conf *Conf) []Repo { } } } + + exclude := GetExcludedMap(repo.Exclude) + for _, r := range gitlabrepos { + if exclude[r.Name] { + continue + } repos = append(repos, Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo}) } groups, _, err := client.Groups.ListGroups(&gitlab.ListGroupsOptions{}) @@ -416,6 +445,9 @@ func getGitlab(conf *Conf) []Repo { } } for _, r := range gitlabgrouprepos { + if exclude[r.Name] { + continue + } repos = append(repos, Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo}) } } @@ -442,7 +474,13 @@ func getBitbucket(conf *Conf) []Repo { if err != nil { log.Panic().Str("stage", "bitbucket").Str("url", repo.Url).Msg(err.Error()) } + + exclude := GetExcludedMap(repo.Exclude) + for _, r := range repositories.Items { + if exclude[r.Name] { + continue + } repos = append(repos, Repo{Name: r.Name, Url: r.Links["clone"].([]interface{})[0].(map[string]interface{})["href"].(string), SshUrl: r.Links["clone"].([]interface{})[1].(map[string]interface{})["href"].(string), Token: "", Defaultbranch: r.Mainbranch.Name, Origin: repo}) } } diff --git a/types.go b/types.go index d7f953a..c16ff01 100644 --- a/types.go +++ b/types.go @@ -31,13 +31,14 @@ type Source struct { // Generell Repo type GenRepo struct { - Token string `yaml:"token"` - User string `yaml:"user"` - SSH bool `yaml:"ssh"` - SSHKey string `yaml:"sshkey"` - Username string `yaml:"username"` - Password string `yaml:"password"` - Url string `yaml:"url"` + Token string `yaml:"token"` + User string `yaml:"user"` + SSH bool `yaml:"ssh"` + SSHKey string `yaml:"sshkey"` + Username string `yaml:"username"` + Password string `yaml:"password"` + Url string `yaml:"url"` + Exclude []string `yaml:"exclude"` } // Repo From f896b2e61161654e46eeac4a4a44c4f51c634bc8 Mon Sep 17 00:00:00 2001 From: Andreas Wachter Date: Thu, 2 Dec 2021 18:59:16 +0100 Subject: [PATCH 2/2] includes "exclude" in the readme --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 64f9d4f..46561ef 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ source: password: bla ssh: true # can be true or false sshkey: /path/to/key # if empty, it uses your home directories' .ssh/id_rsa + exclude: # this excludes the repos foo and bar + - foo + - bar gitea: - token: blabla user: blabla @@ -31,6 +34,9 @@ source: password: bla ssh: true # can be true or false sshkey: /path/to/key # if empty, it uses your home directories' .ssh/id_rsa + exclude: # this excludes the repos foo and bar + - foo + - bar gogs: - token: blabla user: blabla @@ -39,6 +45,9 @@ source: password: bla ssh: true # can be true or false sshkey: /path/to/key # if empty, it uses your home directories' .ssh/id_rsa + exclude: # this excludes the repos foo and bar + - foo + - bar gitlab: - token: blabla user: blabla @@ -47,6 +56,9 @@ source: password: bla ssh: true # can be true or false sshkey: /path/to/key # if empty, it uses your home directories' .ssh/id_rsa + exclude: # this excludes the repos foo and bar + - foo + - bar bitbucket: - user: blabla url: blabla @@ -54,6 +66,9 @@ source: password: blabla ssh: true # can be true or false sshkey: /path/to/key # if empty, it uses your home directories' .ssh/id_rsa + exclude: # this excludes the repos foo and bar + - foo + - bar destination: gitea: - token: blabla