diff --git a/conf.example.yml b/conf.example.yml index 7745d3d..415e5e3 100644 --- a/conf.example.yml +++ b/conf.example.yml @@ -199,6 +199,7 @@ destination: user: some-name # can be a user or an organization, it must exist on the system url: http(s)://url-to-gitea createorg: true # creates an organization if it doesn't exist already, if no user is set it creates an organization with the name of the original author + mirrorinterval: 2h0m0s # interval to pull changes from source repo visibility: repositories: private # private, public, default: private organizations: private # private, limited, public, default: private diff --git a/gitea/gitea.go b/gitea/gitea.go index 7e38382..b59b641 100644 --- a/gitea/gitea.go +++ b/gitea/gitea.go @@ -100,27 +100,29 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) bool { repo, _, err := giteaclient.GetRepo(user.UserName, r.Name) if err != nil { opts := gitea.MigrateRepoOption{ - RepoName: r.Name, - RepoOwner: user.UserName, - Mirror: true, - CloneAddr: r.URL, - AuthToken: r.Token, - Wiki: r.Origin.Wiki, - Private: repovisibility, - Description: r.Description, + RepoName: r.Name, + RepoOwner: user.UserName, + Mirror: true, + CloneAddr: r.URL, + AuthToken: r.Token, + Wiki: r.Origin.Wiki, + Private: repovisibility, + Description: r.Description, + MirrorInterval: d.MirrorInterval, } if r.Token == "" { opts = gitea.MigrateRepoOption{ - RepoName: r.Name, - RepoOwner: user.UserName, - Mirror: true, - CloneAddr: r.URL, - AuthUsername: r.Origin.User, - AuthPassword: r.Origin.Password, - Wiki: r.Origin.Wiki, - Private: repovisibility, - Description: r.Description, + RepoName: r.Name, + RepoOwner: user.UserName, + Mirror: true, + CloneAddr: r.URL, + AuthUsername: r.Origin.User, + AuthPassword: r.Origin.Password, + Wiki: r.Origin.Wiki, + Private: repovisibility, + Description: r.Description, + MirrorInterval: d.MirrorInterval, } } @@ -130,6 +132,17 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) bool { Str("stage", "gitea"). Str("url", d.URL). Msg(err.Error()) + log.Info(). + Str("stage", "gitea"). + Str("url", d.URL). + Msgf("deleting %s again", types.Blue(r.Name)) + _, err = giteaclient.DeleteRepo(user.UserName, r.Name) + if err != nil { + log.Error(). + Str("stage", "gitea"). + Str("url", d.URL). + Msgf("couldn't delete %s!", types.Red(r.Name)) + } return false } diff --git a/gogs/gogs.go b/gogs/gogs.go index 19a316a..61eed22 100644 --- a/gogs/gogs.go +++ b/gogs/gogs.go @@ -103,6 +103,17 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) bool { Str("stage", "gogs"). Str("url", d.URL). Msg(err.Error()) + log.Info(). + Str("stage", "gogs"). + Str("url", d.URL). + Msgf("deleting %s again", types.Blue(r.Name)) + err = gogsclient.DeleteRepo(user.UserName, r.Name) + if err != nil { + log.Error(). + Str("stage", "gogs"). + Str("url", d.URL). + Msgf("couldn't delete %s!", types.Red(r.Name)) + } return false } diff --git a/types/types.go b/types/types.go index 7ada8d1..bf2a55c 100644 --- a/types/types.go +++ b/types/types.go @@ -228,26 +228,27 @@ func (source Source) Count() int { // GenRepo Generell Repo. type GenRepo struct { - Token string `yaml:"token"` - TokenFile string `yaml:"token_file"` - User string `yaml:"user"` - Organization string `yaml:"organization"` - SSH bool `yaml:"ssh"` - SSHKey string `yaml:"sshkey"` - Username string `yaml:"username"` - Password string `yaml:"password"` - URL string `yaml:"url"` - Exclude []string `yaml:"exclude"` - ExcludeOrgs []string `yaml:"excludeorgs"` - Include []string `yaml:"include"` - IncludeOrgs []string `yaml:"includeorgs"` - Wiki bool `yaml:"wiki"` - Starred bool `yaml:"starred"` - CreateOrg bool `yaml:"createorg"` - Visibility Visibility `yaml:"visibility"` - Filter Filter `yaml:"filter"` - Force bool `yaml:"force"` - Contributed bool `yaml:"contributed"` + Token string `yaml:"token"` + TokenFile string `yaml:"token_file"` + User string `yaml:"user"` + Organization string `yaml:"organization"` + SSH bool `yaml:"ssh"` + SSHKey string `yaml:"sshkey"` + Username string `yaml:"username"` + Password string `yaml:"password"` + URL string `yaml:"url"` + Exclude []string `yaml:"exclude"` + ExcludeOrgs []string `yaml:"excludeorgs"` + Include []string `yaml:"include"` + IncludeOrgs []string `yaml:"includeorgs"` + Wiki bool `yaml:"wiki"` + Starred bool `yaml:"starred"` + CreateOrg bool `yaml:"createorg"` + Visibility Visibility `yaml:"visibility"` + Filter Filter `yaml:"filter"` + Force bool `yaml:"force"` + Contributed bool `yaml:"contributed"` + MirrorInterval string `yaml:"mirrorinterval"` } // Visibility struct