mirror of
https://github.com/cooperspencer/gickup
synced 2024-10-18 07:38:08 +02:00
mirror is now a struct
This commit is contained in:
parent
a26bbe84ca
commit
0b32890b8c
@ -205,8 +205,11 @@ 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
|
||||
mirrorinterval: 2h0m0s # interval to pull changes from source repo, will be removed in one of the next releases
|
||||
lfs: false # trigger to enable lfs on gitea
|
||||
mirror:
|
||||
enabled: true # if set to true, gickup will clone the repository and push it to gitea itself
|
||||
mirrorinterval: 2h0m0s # interval to pull changes from source repo
|
||||
visibility:
|
||||
repositories: private # private, public, default: private
|
||||
organizations: private # private, limited, public, default: private
|
||||
@ -216,6 +219,8 @@ destination:
|
||||
user: some-name # can be a user or an organization, it must exist on the system
|
||||
url: http(s)://url-to-gogs
|
||||
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
|
||||
mirror:
|
||||
enabled: true # if set to true, gickup will clone the repository and push it to gogs itself
|
||||
visibility:
|
||||
repositories: private # private, public, default: private
|
||||
gitlab:
|
||||
|
@ -41,9 +41,6 @@ func getRepoVisibility(visibility string, private bool) bool {
|
||||
|
||||
// Backup TODO.
|
||||
func Backup(r types.Repo, d types.GenRepo, dry bool) bool {
|
||||
if d.MirrorInterval == "" {
|
||||
d.MirrorInterval = "8h0m0s"
|
||||
}
|
||||
orgvisibilty := getOrgVisibility(d.Visibility.Organizations)
|
||||
repovisibility := getRepoVisibility(d.Visibility.Repositories, r.Private)
|
||||
if d.URL == "" {
|
||||
@ -53,6 +50,20 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) bool {
|
||||
sub.Info().
|
||||
Msgf("mirroring %s to %s", types.Blue(r.Name), d.URL)
|
||||
|
||||
mirrorInterval := "8h0m0s"
|
||||
|
||||
if d.MirrorInterval != "" {
|
||||
sub.Warn().Msg("mirrorinterval is deprecated and will be removed in one of the next releases. please move it under the mirror parameter.")
|
||||
}
|
||||
|
||||
if d.MirrorInterval != "" {
|
||||
mirrorInterval = d.MirrorInterval
|
||||
}
|
||||
|
||||
if d.Mirror.MirrorInterval != "" {
|
||||
mirrorInterval = d.Mirror.MirrorInterval
|
||||
}
|
||||
|
||||
giteaclient, err := gitea.NewClient(d.URL, gitea.SetToken(d.GetToken()))
|
||||
if err != nil {
|
||||
sub.Error().Msg(err.Error())
|
||||
@ -109,7 +120,7 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) bool {
|
||||
Wiki: r.Origin.Wiki,
|
||||
Private: repovisibility,
|
||||
Description: r.Description,
|
||||
MirrorInterval: d.MirrorInterval,
|
||||
MirrorInterval: mirrorInterval,
|
||||
LFS: d.LFS,
|
||||
}
|
||||
|
||||
@ -124,7 +135,7 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) bool {
|
||||
Wiki: r.Origin.Wiki,
|
||||
Private: repovisibility,
|
||||
Description: r.Description,
|
||||
MirrorInterval: d.MirrorInterval,
|
||||
MirrorInterval: mirrorInterval,
|
||||
LFS: d.LFS,
|
||||
}
|
||||
}
|
||||
@ -151,16 +162,16 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if d.MirrorInterval != "" {
|
||||
_, err = time.ParseDuration(d.MirrorInterval)
|
||||
if mirrorInterval != "" {
|
||||
_, err = time.ParseDuration(mirrorInterval)
|
||||
if err != nil {
|
||||
sub.Warn().Msgf("%s is not a valid duration!", d.MirrorInterval)
|
||||
d.MirrorInterval = repo.MirrorInterval
|
||||
sub.Warn().Msgf("%s is not a valid duration!", mirrorInterval)
|
||||
mirrorInterval = repo.MirrorInterval
|
||||
}
|
||||
}
|
||||
|
||||
if d.MirrorInterval != repo.MirrorInterval {
|
||||
_, _, err := giteaclient.EditRepo(user.UserName, r.Name, gitea.EditRepoOption{MirrorInterval: &d.MirrorInterval})
|
||||
if mirrorInterval != repo.MirrorInterval {
|
||||
_, _, err := giteaclient.EditRepo(user.UserName, r.Name, gitea.EditRepoOption{MirrorInterval: &mirrorInterval})
|
||||
if err != nil {
|
||||
sub.Error().
|
||||
Err(err).
|
||||
|
4
main.go
4
main.go
@ -187,7 +187,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
if !strings.HasSuffix(r.Name, ".wiki") {
|
||||
repotime := time.Now()
|
||||
status := 0
|
||||
if d.SelfMirror {
|
||||
if d.Mirror.Enabled {
|
||||
log.Info().
|
||||
Str("stage", "gitea").
|
||||
Str("url", d.URL).
|
||||
@ -272,7 +272,7 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
||||
if !strings.HasSuffix(r.Name, ".wiki") {
|
||||
repotime := time.Now()
|
||||
status := 0
|
||||
if d.SelfMirror {
|
||||
if d.Mirror.Enabled {
|
||||
log.Info().
|
||||
Str("stage", "gogs").
|
||||
Str("url", d.URL).
|
||||
|
@ -251,7 +251,13 @@ type GenRepo struct {
|
||||
Contributed bool `yaml:"contributed"`
|
||||
MirrorInterval string `yaml:"mirrorinterval"`
|
||||
LFS bool `yaml:"lfs"`
|
||||
SelfMirror bool `yaml:"selfmirror"`
|
||||
Mirror Mirror `yaml:"mirror"`
|
||||
}
|
||||
|
||||
// Mirror struct
|
||||
type Mirror struct {
|
||||
MirrorInterval string `yaml:"mirrorinterval"`
|
||||
Enabled bool `yaml:"enabled"`
|
||||
}
|
||||
|
||||
// Visibility struct
|
||||
|
Loading…
Reference in New Issue
Block a user