Skip to content

Commit bac2883

Browse files
zeripathGustedwxiaoguanglunnytechknowlogick
authored andcommitted
Ensure minimum mirror interval is reported on settings page (go-gitea#19895)
* Ensure minimum mirror interval is reported on settings page Expecting users to guess the minimum mirror interval appears a little unkind. In this PR we simply change the locale string to include the minimum interval. This will of course be affected by our current localization framework but... we can fix that else where. This PR also includes some fixes for error handling on the settings page as previously the mirror block amongst others would simply disappear on error. Fix go-gitea#3737 Signed-off-by: Andrew Thornton <[email protected]> * Update options/locale/locale_en-US.ini Co-authored-by: Gusted <[email protected]> * placate lint Signed-off-by: Andrew Thornton <[email protected]> * Update options/locale/locale_en-US.ini Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: Gusted <[email protected]> Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent e6b1c1b commit bac2883

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ default_branch = Default Branch
860860
default_branch_helper = The default branch is the base branch for pull requests and code commits.
861861
mirror_prune = Prune
862862
mirror_prune_desc = Remove obsolete remote-tracking references
863-
mirror_interval = Mirror Interval (valid time units are 'h', 'm', 's'). 0 to disable automatic sync.
863+
mirror_interval = Mirror Interval (valid time units are 'h', 'm', 's'). 0 to disable automatic sync. (Minimum interval: %s)
864864
mirror_interval_invalid = The mirror interval is not valid.
865865
mirror_address = Clone From URL
866866
mirror_address_desc = Put any required credentials in the Authorization section.

routers/web/repo/setting.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ func Settings(ctx *context.Context) {
6565
ctx.Data["MirrorsEnabled"] = setting.Mirror.Enabled
6666
ctx.Data["DisableNewPushMirrors"] = setting.Mirror.DisableNewPush
6767
ctx.Data["DefaultMirrorInterval"] = setting.Mirror.DefaultInterval
68+
ctx.Data["MinimumMirrorInterval"] = setting.Mirror.MinInterval
6869

6970
signing, _ := asymkey_service.SigningKey(ctx, ctx.Repo.Repository.RepoPath())
7071
ctx.Data["SigningKeyAvailable"] = len(signing) > 0
7172
ctx.Data["SigningSettings"] = setting.Repository.Signing
7273
ctx.Data["CodeIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
74+
7375
if ctx.Doer.IsAdmin {
7476
if setting.Indexer.RepoIndexerEnabled {
7577
status, err := repo_model.GetIndexerStatus(ctx, ctx.Repo.Repository, repo_model.RepoIndexerTypeCode)
@@ -102,6 +104,17 @@ func SettingsPost(ctx *context.Context) {
102104
ctx.Data["Title"] = ctx.Tr("repo.settings")
103105
ctx.Data["PageIsSettingsOptions"] = true
104106

107+
ctx.Data["ForcePrivate"] = setting.Repository.ForcePrivate
108+
ctx.Data["MirrorsEnabled"] = setting.Mirror.Enabled
109+
ctx.Data["DisableNewPushMirrors"] = setting.Mirror.DisableNewPush
110+
ctx.Data["DefaultMirrorInterval"] = setting.Mirror.DefaultInterval
111+
ctx.Data["MinimumMirrorInterval"] = setting.Mirror.MinInterval
112+
113+
signing, _ := asymkey_service.SigningKey(ctx, ctx.Repo.Repository.RepoPath())
114+
ctx.Data["SigningKeyAvailable"] = len(signing) > 0
115+
ctx.Data["SigningSettings"] = setting.Repository.Signing
116+
ctx.Data["CodeIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
117+
105118
repo := ctx.Repo.Repository
106119

107120
switch ctx.FormString("action") {
@@ -191,15 +204,15 @@ func SettingsPost(ctx *context.Context) {
191204
if err != nil || (interval != 0 && interval < setting.Mirror.MinInterval) {
192205
ctx.Data["Err_Interval"] = true
193206
ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form)
194-
} else {
195-
ctx.Repo.Mirror.EnablePrune = form.EnablePrune
196-
ctx.Repo.Mirror.Interval = interval
197-
ctx.Repo.Mirror.ScheduleNextUpdate()
198-
if err := repo_model.UpdateMirror(ctx, ctx.Repo.Mirror); err != nil {
199-
ctx.Data["Err_Interval"] = true
200-
ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form)
201-
return
202-
}
207+
return
208+
}
209+
210+
ctx.Repo.Mirror.EnablePrune = form.EnablePrune
211+
ctx.Repo.Mirror.Interval = interval
212+
ctx.Repo.Mirror.ScheduleNextUpdate()
213+
if err := repo_model.UpdateMirror(ctx, ctx.Repo.Mirror); err != nil {
214+
ctx.ServerError("UpdateMirror", err)
215+
return
203216
}
204217

205218
u, _ := git.GetRemoteAddress(ctx, ctx.Repo.Repository.RepoPath(), ctx.Repo.Mirror.GetRemoteName())

templates/repo/settings/options.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
</div>
117117
</div>
118118
<div class="inline field {{if .Err_Interval}}error{{end}}">
119-
<label for="interval">{{.i18n.Tr "repo.mirror_interval"}}</label>
119+
<label for="interval">{{.i18n.Tr "repo.mirror_interval" .MinimumMirrorInterval}}</label>
120120
<input id="interval" name="interval" value="{{.MirrorInterval}}">
121121
</div>
122122
{{$address := MirrorRemoteAddress $.Context .Mirror}}
@@ -220,7 +220,7 @@
220220
</div>
221221
</details>
222222
<div class="inline field {{if .Err_PushMirrorInterval}}error{{end}}">
223-
<label for="push_mirror_interval">{{.i18n.Tr "repo.mirror_interval"}}</label>
223+
<label for="push_mirror_interval">{{.i18n.Tr "repo.mirror_interval" .MinimumMirrorInterval}}</label>
224224
<input id="push_mirror_interval" name="push_mirror_interval" value="{{if .push_mirror_interval}}{{.push_mirror_interval}}{{else}}{{.DefaultMirrorInterval}}{{end}}">
225225
</div>
226226
<div class="field">

0 commit comments

Comments
 (0)