diff options
author | Paul Barton <28630076+paulbarton90@users.noreply.github.com> | 2021-01-02 23:47:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-02 18:47:47 -0500 |
commit | 7576e37a65729363370d6672ff6e69e87b68ac5f (patch) | |
tree | c2e885826e6f744b88949c9451d6a206ff48abcd /modules/repository | |
parent | 3abea9e9eb8cbe42d1ec0afa70b4941d4066130f (diff) | |
download | gitea-7576e37a65729363370d6672ff6e69e87b68ac5f.tar.gz gitea-7576e37a65729363370d6672ff6e69e87b68ac5f.zip |
Add MirrorInterval to the API (#14163)
* Added MirrorInterval to the API
* Remove MirrorInterval from CreateRepository
* Removed Duplicate UpdateMirror Function
* Updated Error Logging
* Update Log Message for is not Mirror
Co-authored-by: 6543 <6543@obermui.de>
* Delete Debug Statement that snuck in
Co-authored-by: zeripath <art27@cantab.net>
* Add Check for If Interval is too small
* Output to API Call
* Add Error Object when time is Less than Min Interval
* Frequency Error Message
Co-authored-by: zeripath <art27@cantab.net>
* Allow Zero Mirror Interval
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules/repository')
-rw-r--r-- | modules/repository/repo.go | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/modules/repository/repo.go b/modules/repository/repo.go index 8ecb43ede6..ede714673a 100644 --- a/modules/repository/repo.go +++ b/modules/repository/repo.go @@ -127,12 +127,33 @@ func MigrateRepositoryGitData(ctx context.Context, u *models.User, repo *models. } if opts.Mirror { - if err = models.InsertMirror(&models.Mirror{ + mirrorModel := models.Mirror{ RepoID: repo.ID, Interval: setting.Mirror.DefaultInterval, EnablePrune: true, NextUpdateUnix: timeutil.TimeStampNow().AddDuration(setting.Mirror.DefaultInterval), - }); err != nil { + } + + if opts.MirrorInterval != "" { + parsedInterval, err := time.ParseDuration(opts.MirrorInterval) + if err != nil { + log.Error("Failed to set Interval: %v", err) + return repo, err + } + if parsedInterval == 0 { + mirrorModel.Interval = 0 + mirrorModel.NextUpdateUnix = 0 + } else if parsedInterval < setting.Mirror.MinInterval { + err := fmt.Errorf("Interval %s is set below Minimum Interval of %s", parsedInterval, setting.Mirror.MinInterval) + log.Error("Interval: %s is too frequent", opts.MirrorInterval) + return repo, err + } else { + mirrorModel.Interval = parsedInterval + mirrorModel.NextUpdateUnix = timeutil.TimeStampNow().AddDuration(parsedInterval) + } + } + + if err = models.InsertMirror(&mirrorModel); err != nil { return repo, fmt.Errorf("InsertOne: %v", err) } |