Skip to content

Commit de73a85

Browse files
Merge pull request #15 from cooperspencer/exclude-list
added function to exclude repos
2 parents 6972bbd + f896b2e commit de73a85

5 files changed

Lines changed: 70 additions & 20 deletions

File tree

.github/workflows/go.yml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,8 @@ jobs:
2020
with:
2121
go-version: 1.17
2222

23-
- name: Build
24-
run: go build -v ./...
25-
2623
- name: Test
2724
run: go test -v ./...
28-
29-
- name: Upload a Build Artifact
30-
uses: actions/upload-artifact@v2.2.3
31-
with:
32-
# Artifact name
33-
name: gickup
34-
# A file, directory or wildcard pattern that describes what to upload
35-
path: gickup
3625

3726
- name: Run GoReleaser
3827
uses: goreleaser/goreleaser-action@v2
@@ -42,4 +31,10 @@ jobs:
4231
version: latest
4332
args: release --rm-dist
4433
env:
45-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Upload a Build Artifact
37+
uses: actions/upload-artifact@v2
38+
with:
39+
name: gickup
40+
path: dist/*

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bla.conf
2-
gickup
2+
gickup
3+
conf.yml

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ source:
2323
password: bla
2424
ssh: true # can be true or false
2525
sshkey: /path/to/key # if empty, it uses your home directories' .ssh/id_rsa
26+
exclude: # this excludes the repos foo and bar
27+
- foo
28+
- bar
2629
gitea:
2730
- token: blabla
2831
user: blabla
@@ -31,6 +34,9 @@ source:
3134
password: bla
3235
ssh: true # can be true or false
3336
sshkey: /path/to/key # if empty, it uses your home directories' .ssh/id_rsa
37+
exclude: # this excludes the repos foo and bar
38+
- foo
39+
- bar
3440
gogs:
3541
- token: blabla
3642
user: blabla
@@ -39,6 +45,9 @@ source:
3945
password: bla
4046
ssh: true # can be true or false
4147
sshkey: /path/to/key # if empty, it uses your home directories' .ssh/id_rsa
48+
exclude: # this excludes the repos foo and bar
49+
- foo
50+
- bar
4251
gitlab:
4352
- token: blabla
4453
user: blabla
@@ -47,13 +56,19 @@ source:
4756
password: bla
4857
ssh: true # can be true or false
4958
sshkey: /path/to/key # if empty, it uses your home directories' .ssh/id_rsa
59+
exclude: # this excludes the repos foo and bar
60+
- foo
61+
- bar
5062
bitbucket:
5163
- user: blabla
5264
url: blabla
5365
username: blabla
5466
password: blabla
5567
ssh: true # can be true or false
5668
sshkey: /path/to/key # if empty, it uses your home directories' .ssh/id_rsa
69+
exclude: # this excludes the repos foo and bar
70+
- foo
71+
- bar
5772
destination:
5873
gitea:
5974
- token: blabla

main.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ func ReadConfigfile(configfile string) *Conf {
5555
return &t
5656
}
5757

58+
func GetExcludedMap(excludes []string) map[string]bool {
59+
excludemap := make(map[string]bool)
60+
for _, exclude := range excludes {
61+
excludemap[exclude] = true
62+
}
63+
return excludemap
64+
}
65+
5866
func Locally(repo Repo, l Local) {
5967
if _, err := os.Stat(l.Path); os.IsNotExist(err) {
6068
err := os.MkdirAll(l.Path, 0777)
@@ -288,7 +296,12 @@ func getGithub(conf *Conf) []Repo {
288296
i++
289297
}
290298

299+
exclude := GetExcludedMap(repo.Exclude)
300+
291301
for _, r := range githubrepos {
302+
if exclude[*r.Name] {
303+
continue
304+
}
292305
repos = append(repos, Repo{Name: r.GetName(), Url: r.GetCloneURL(), SshUrl: r.GetSSHURL(), Token: repo.Token, Defaultbranch: r.GetDefaultBranch(), Origin: repo})
293306
}
294307
}
@@ -326,7 +339,12 @@ func getGitea(conf *Conf) []Repo {
326339
i++
327340
}
328341

342+
exclude := GetExcludedMap(repo.Exclude)
343+
329344
for _, r := range gitearepos {
345+
if exclude[r.Name] {
346+
continue
347+
}
330348
repos = append(repos, Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
331349
}
332350
}
@@ -343,7 +361,12 @@ func getGogs(conf *Conf) []Repo {
343361
log.Panic().Str("stage", "gogs").Str("url", repo.Url).Msg(err.Error())
344362
}
345363

364+
exclude := GetExcludedMap(repo.Exclude)
365+
346366
for _, r := range gogsrepos {
367+
if exclude[r.Name] {
368+
continue
369+
}
347370
repos = append(repos, Repo{Name: r.Name, Url: r.CloneURL, SshUrl: r.SSHURL, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
348371
}
349372
}
@@ -387,7 +410,13 @@ func getGitlab(conf *Conf) []Repo {
387410
}
388411
}
389412
}
413+
414+
exclude := GetExcludedMap(repo.Exclude)
415+
390416
for _, r := range gitlabrepos {
417+
if exclude[r.Name] {
418+
continue
419+
}
391420
repos = append(repos, Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
392421
}
393422
groups, _, err := client.Groups.ListGroups(&gitlab.ListGroupsOptions{})
@@ -416,6 +445,9 @@ func getGitlab(conf *Conf) []Repo {
416445
}
417446
}
418447
for _, r := range gitlabgrouprepos {
448+
if exclude[r.Name] {
449+
continue
450+
}
419451
repos = append(repos, Repo{Name: r.Name, Url: r.HTTPURLToRepo, SshUrl: r.SSHURLToRepo, Token: repo.Token, Defaultbranch: r.DefaultBranch, Origin: repo})
420452
}
421453
}
@@ -442,7 +474,13 @@ func getBitbucket(conf *Conf) []Repo {
442474
if err != nil {
443475
log.Panic().Str("stage", "bitbucket").Str("url", repo.Url).Msg(err.Error())
444476
}
477+
478+
exclude := GetExcludedMap(repo.Exclude)
479+
445480
for _, r := range repositories.Items {
481+
if exclude[r.Name] {
482+
continue
483+
}
446484
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})
447485
}
448486
}

types.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ type Source struct {
3131

3232
// Generell Repo
3333
type GenRepo struct {
34-
Token string `yaml:"token"`
35-
User string `yaml:"user"`
36-
SSH bool `yaml:"ssh"`
37-
SSHKey string `yaml:"sshkey"`
38-
Username string `yaml:"username"`
39-
Password string `yaml:"password"`
40-
Url string `yaml:"url"`
34+
Token string `yaml:"token"`
35+
User string `yaml:"user"`
36+
SSH bool `yaml:"ssh"`
37+
SSHKey string `yaml:"sshkey"`
38+
Username string `yaml:"username"`
39+
Password string `yaml:"password"`
40+
Url string `yaml:"url"`
41+
Exclude []string `yaml:"exclude"`
4142
}
4243

4344
// Repo

0 commit comments

Comments
 (0)