From d7959c77b8d7b9581080e9ed31217926a03eaae5 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sun, 5 Jun 2022 20:09:40 +0100 Subject: [PATCH 1/4] 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 #3737 Signed-off-by: Andrew Thornton --- options/locale/locale_en-US.ini | 3 ++- routers/web/repo/setting.go | 17 +++++++++++++++-- templates/repo/settings/options.tmpl | 4 ++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index d52fe0556949..b4dd634f0b7f 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -860,7 +860,7 @@ default_branch = Default Branch default_branch_helper = The default branch is the base branch for pull requests and code commits. mirror_prune = Prune mirror_prune_desc = Remove obsolete remote-tracking references -mirror_interval = Mirror Interval (valid time units are 'h', 'm', 's'). 0 to disable automatic sync. +mirror_interval = Mirror Interval (valid time units are 'h', 'm', 's'). 0 to disable automatic sync. (Minimum interval: %v) mirror_interval_invalid = The mirror interval is not valid. mirror_address = Clone From URL mirror_address_desc = Put any required credentials in the Authorization section. @@ -1532,6 +1532,7 @@ pulls.data_broken = This pull request is broken due to missing fork information. pulls.files_conflicted = This pull request has changes conflicting with the target branch. pulls.is_checking = "Merge conflict checking is in progress. Try again in few moments." pulls.is_empty = "This branch is equal with the target branch." +pulls.is_empty_differing_head_merge_base = "This branch ." pulls.required_status_check_failed = Some required checks were not successful. pulls.required_status_check_missing = Some required checks are missing. pulls.required_status_check_administrator = As an administrator, you may still merge this pull request. diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index a60bf5262216..0f01c907aa39 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -65,11 +65,13 @@ func Settings(ctx *context.Context) { ctx.Data["MirrorsEnabled"] = setting.Mirror.Enabled ctx.Data["DisableNewPushMirrors"] = setting.Mirror.DisableNewPush ctx.Data["DefaultMirrorInterval"] = setting.Mirror.DefaultInterval + ctx.Data["MinimumMirrorInterval"] = setting.Mirror.MinInterval signing, _ := asymkey_service.SigningKey(ctx, ctx.Repo.Repository.RepoPath()) ctx.Data["SigningKeyAvailable"] = len(signing) > 0 ctx.Data["SigningSettings"] = setting.Repository.Signing ctx.Data["CodeIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled + if ctx.Doer.IsAdmin { if setting.Indexer.RepoIndexerEnabled { status, err := repo_model.GetIndexerStatus(ctx, ctx.Repo.Repository, repo_model.RepoIndexerTypeCode) @@ -102,6 +104,17 @@ func SettingsPost(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsOptions"] = true + ctx.Data["ForcePrivate"] = setting.Repository.ForcePrivate + ctx.Data["MirrorsEnabled"] = setting.Mirror.Enabled + ctx.Data["DisableNewPushMirrors"] = setting.Mirror.DisableNewPush + ctx.Data["DefaultMirrorInterval"] = setting.Mirror.DefaultInterval + ctx.Data["MinimumMirrorInterval"] = setting.Mirror.MinInterval + + signing, _ := asymkey_service.SigningKey(ctx, ctx.Repo.Repository.RepoPath()) + ctx.Data["SigningKeyAvailable"] = len(signing) > 0 + ctx.Data["SigningSettings"] = setting.Repository.Signing + ctx.Data["CodeIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled + repo := ctx.Repo.Repository switch ctx.FormString("action") { @@ -191,13 +204,13 @@ func SettingsPost(ctx *context.Context) { if err != nil || (interval != 0 && interval < setting.Mirror.MinInterval) { ctx.Data["Err_Interval"] = true ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form) + return } else { ctx.Repo.Mirror.EnablePrune = form.EnablePrune ctx.Repo.Mirror.Interval = interval ctx.Repo.Mirror.ScheduleNextUpdate() if err := repo_model.UpdateMirror(ctx, ctx.Repo.Mirror); err != nil { - ctx.Data["Err_Interval"] = true - ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form) + ctx.ServerError("UpdateMirror", err) return } } diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index e2d6c5e1d503..f44d9c98ad78 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -116,7 +116,7 @@
- +
{{$address := MirrorRemoteAddress $.Context .Mirror}} @@ -220,7 +220,7 @@
- +
From 8558a8eca9d2a0495f6a3b20f45929adbb91470f Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 5 Jun 2022 21:09:31 +0100 Subject: [PATCH 2/4] Update options/locale/locale_en-US.ini Co-authored-by: Gusted --- options/locale/locale_en-US.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index b4dd634f0b7f..6a5b3869bef3 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -860,7 +860,7 @@ default_branch = Default Branch default_branch_helper = The default branch is the base branch for pull requests and code commits. mirror_prune = Prune mirror_prune_desc = Remove obsolete remote-tracking references -mirror_interval = Mirror Interval (valid time units are 'h', 'm', 's'). 0 to disable automatic sync. (Minimum interval: %v) +mirror_interval = Mirror Interval (valid time units are 'h', 'm', 's'). 0 to disable automatic sync. (Minimum interval: %s) mirror_interval_invalid = The mirror interval is not valid. mirror_address = Clone From URL mirror_address_desc = Put any required credentials in the Authorization section. From 8bfe99c436135482d783a1f2b8e556f170bc5384 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sun, 5 Jun 2022 21:18:36 +0100 Subject: [PATCH 3/4] placate lint Signed-off-by: Andrew Thornton --- routers/web/repo/setting.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index 0f01c907aa39..4fd5ef442cee 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -205,14 +205,14 @@ func SettingsPost(ctx *context.Context) { ctx.Data["Err_Interval"] = true ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form) return - } else { - ctx.Repo.Mirror.EnablePrune = form.EnablePrune - ctx.Repo.Mirror.Interval = interval - ctx.Repo.Mirror.ScheduleNextUpdate() - if err := repo_model.UpdateMirror(ctx, ctx.Repo.Mirror); err != nil { - ctx.ServerError("UpdateMirror", err) - return - } + } + + ctx.Repo.Mirror.EnablePrune = form.EnablePrune + ctx.Repo.Mirror.Interval = interval + ctx.Repo.Mirror.ScheduleNextUpdate() + if err := repo_model.UpdateMirror(ctx, ctx.Repo.Mirror); err != nil { + ctx.ServerError("UpdateMirror", err) + return } u, _ := git.GetRemoteAddress(ctx, ctx.Repo.Repository.RepoPath(), ctx.Repo.Mirror.GetRemoteName()) From 95cf2bfeb66697accf40efcbc4935e936d5d1301 Mon Sep 17 00:00:00 2001 From: zeripath Date: Mon, 6 Jun 2022 19:07:56 +0100 Subject: [PATCH 4/4] Update options/locale/locale_en-US.ini Co-authored-by: wxiaoguang --- options/locale/locale_en-US.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 6a5b3869bef3..2c2e85ca2e64 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1532,7 +1532,6 @@ pulls.data_broken = This pull request is broken due to missing fork information. pulls.files_conflicted = This pull request has changes conflicting with the target branch. pulls.is_checking = "Merge conflict checking is in progress. Try again in few moments." pulls.is_empty = "This branch is equal with the target branch." -pulls.is_empty_differing_head_merge_base = "This branch ." pulls.required_status_check_failed = Some required checks were not successful. pulls.required_status_check_missing = Some required checks are missing. pulls.required_status_check_administrator = As an administrator, you may still merge this pull request.