Skip to content

Commit

Permalink
mirror is now a struct
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperspencer committed Apr 12, 2024
1 parent a26bbe8 commit 0b32890
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
7 changes: 6 additions & 1 deletion conf.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
33 changes: 22 additions & 11 deletions gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand All @@ -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())
Expand Down Expand Up @@ -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,
}

Expand All @@ -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,
}
}
Expand All @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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).
Expand Down
8 changes: 7 additions & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b32890

Please sign in to comment.