diff --git a/models/repo/pushmirror.go b/models/repo/pushmirror.go index f34484f63878..dad9a9d38851 100644 --- a/models/repo/pushmirror.go +++ b/models/repo/pushmirror.go @@ -85,6 +85,12 @@ func UpdatePushMirror(ctx context.Context, m *PushMirror) error { return err } +// UpdatePushMirrorInterval updates the push-mirror +func UpdatePushMirrorInterval(ctx context.Context, m *PushMirror) error { + _, err := db.GetEngine(ctx).ID(m.ID).Cols("interval").Update(m) + return err +} + func DeletePushMirrors(ctx context.Context, opts PushMirrorOptions) error { if opts.RepoID > 0 { _, err := db.GetEngine(ctx).Where(opts.toConds()).Delete(&PushMirror{}) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 3256d2ba911c..6cb830b6d02c 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1966,6 +1966,8 @@ settings.mirror_settings.last_update = Last update settings.mirror_settings.push_mirror.none = No push mirrors configured settings.mirror_settings.push_mirror.remote_url = Git Remote Repository URL settings.mirror_settings.push_mirror.add = Add Push Mirror +settings.mirror_settings.push_mirror.edit_sync_time = Edit mirror sync interval + settings.sync_mirror = Synchronize Now settings.mirror_sync_in_progress = Mirror synchronization is in progress. Check back in a minute. settings.site = Website diff --git a/routers/web/repo/setting/setting.go b/routers/web/repo/setting/setting.go index b33660ffc9cc..71c1939f2990 100644 --- a/routers/web/repo/setting/setting.go +++ b/routers/web/repo/setting/setting.go @@ -299,6 +299,43 @@ func SettingsPost(ctx *context.Context) { ctx.Flash.Info(ctx.Tr("repo.settings.mirror_sync_in_progress")) ctx.Redirect(repo.Link() + "/settings") + case "push-mirror-update": + if !setting.Mirror.Enabled { + ctx.NotFound("", nil) + return + } + + // This section doesn't require repo_name/RepoName to be set in the form, don't show it + // as an error on the UI for this action + ctx.Data["Err_RepoName"] = nil + + interval, err := time.ParseDuration(form.PushMirrorInterval) + if err != nil || (interval != 0 && interval < setting.Mirror.MinInterval) { + ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &forms.RepoSettingForm{}) + return + } + + id, err := strconv.ParseInt(form.PushMirrorID, 10, 64) + if err != nil { + ctx.ServerError("UpdatePushMirrorIntervalPushMirrorID", err) + return + } + m := &repo_model.PushMirror{ + ID: id, + Interval: interval, + } + if err := repo_model.UpdatePushMirrorInterval(ctx, m); err != nil { + ctx.ServerError("UpdatePushMirrorInterval", err) + return + } + // Background why we are adding it to Queue + // If we observed its implementation in the context of `push-mirror-sync` where it + // is evident that pushing to the queue is necessary for updates. + // So, there are updates within the given interval, it is necessary to update the queue accordingly. + mirror_module.AddPushMirrorToQueue(m.ID) + ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success")) + ctx.Redirect(repo.Link() + "/settings") + case "push-mirror-remove": if !setting.Mirror.Enabled { ctx.NotFound("", nil) diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index f0b030dc54ba..569a576ce682 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -203,17 +203,27 @@ {{$.locale.Tr "repo.settings.mirror_settings.direction.push"}} {{if .LastUpdateUnix}}{{DateTime "full" .LastUpdateUnix}}{{else}}{{$.locale.Tr "never"}}{{end}} {{if .LastError}}
{{$.locale.Tr "error"}}
{{end}} -
- {{$.CsrfTokenHtml}} - - - -
+
{{$.CsrfTokenHtml}} - + +
+
+ {{$.CsrfTokenHtml}} + + +
@@ -980,3 +990,5 @@ {{end}} {{end}} + +{{template "repo/settings/push_mirror_sync_modal" .}} diff --git a/templates/repo/settings/push_mirror_sync_modal.tmpl b/templates/repo/settings/push_mirror_sync_modal.tmpl new file mode 100644 index 000000000000..a04574add57d --- /dev/null +++ b/templates/repo/settings/push_mirror_sync_modal.tmpl @@ -0,0 +1,32 @@ +