From 35ce7ca25b5756441949312d79aa6382f98ce8d6 Mon Sep 17 00:00:00 2001 From: "Panagiotis \"Ivory\" Vasilopoulos" Date: Mon, 29 May 2023 11:32:52 +0000 Subject: [PATCH] Hide 'Mirror Settings' when unneeded, improve hints (#24433) Co-authored-by: silverwind Co-authored-by: Giteabot --- options/locale/locale_en-US.ini | 11 +++++++- routers/web/repo/setting.go | 2 ++ templates/repo/settings/options.tmpl | 40 ++++++++++++++++++++++++---- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 16dbb0948..ed7cbef9f 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1913,7 +1913,16 @@ settings.hooks = Webhooks settings.githooks = Git Hooks settings.basic_settings = Basic Settings settings.mirror_settings = Mirror Settings -settings.mirror_settings.docs = Set up your project to automatically push and/or pull changes to/from another repository. Branches, tags, and commits will be synced automatically. How do I mirror repositories? +settings.mirror_settings.docs = Set up your repository to automatically synchronize commits, tags and branches with another repository. +settings.mirror_settings.docs.disabled_pull_mirror.instructions = Set up your project to automatically push commits, tags and branches to another repository. Pull mirrors have been disabled by your site administrator. +settings.mirror_settings.docs.disabled_push_mirror.instructions = Set up your project to automatically pull commits, tags and branches from another repository. +settings.mirror_settings.docs.disabled_push_mirror.pull_mirror_warning = Right now, this can only be done in the "New Migration" menu. For more information, please consult: +settings.mirror_settings.docs.disabled_push_mirror.info = Push mirrors have been disabled by your site administrator. +settings.mirror_settings.docs.no_new_mirrors = Your repository is mirroring changes to or from another repository. Please keep in mind that you can't create any new mirrors at this time. +settings.mirror_settings.docs.can_still_use = Although you can't modify existing mirrors or create new ones, you may still use your existing mirror. +settings.mirror_settings.docs.pull_mirror_instructions = To set up a pull mirror, please consult: +settings.mirror_settings.docs.doc_link_title = How do I mirror repositories? +settings.mirror_settings.docs.pulling_remote_title = Pulling from a remote repository settings.mirror_settings.mirrored_repository = Mirrored repository settings.mirror_settings.direction = Direction settings.mirror_settings.direction.pull = Pull diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index 578b70194..4481ff4f0 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -64,6 +64,7 @@ func SettingsCtxData(ctx *context.Context) { ctx.Data["PageIsSettingsOptions"] = true ctx.Data["ForcePrivate"] = setting.Repository.ForcePrivate ctx.Data["MirrorsEnabled"] = setting.Mirror.Enabled + ctx.Data["DisableNewPullMirrors"] = setting.Mirror.DisableNewPull ctx.Data["DisableNewPushMirrors"] = setting.Mirror.DisableNewPush ctx.Data["DefaultMirrorInterval"] = setting.Mirror.DefaultInterval ctx.Data["MinimumMirrorInterval"] = setting.Mirror.MinInterval @@ -108,6 +109,7 @@ func SettingsPost(ctx *context.Context) { ctx.Data["ForcePrivate"] = setting.Repository.ForcePrivate ctx.Data["MirrorsEnabled"] = setting.Mirror.Enabled + ctx.Data["DisableNewPullMirrors"] = setting.Mirror.DisableNewPull ctx.Data["DisableNewPushMirrors"] = setting.Mirror.DisableNewPush ctx.Data["DefaultMirrorInterval"] = setting.Mirror.DefaultInterval ctx.Data["MinimumMirrorInterval"] = setting.Mirror.MinInterval diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 83a6bc4ba..18a5b0446 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -67,14 +67,44 @@ - {{if .MirrorsEnabled}} + + {{/* These variables exist to make the logic in the Settings window easier to comprehend and are not used later on. */}} + {{$newMirrorsPartiallyEnabled := or (not .DisableNewPullMirrors) (not .DisableNewPushMirrors)}} + {{/* .Repository.IsMirror is not always reliable if the repository is not actively acting as a mirror because of errors. */}} + {{$showMirrorSettings := or $newMirrorsPartiallyEnabled .Repository.IsMirror .PullMirror .PushMirrors}} + {{$newMirrorsEntirelyEnabled := and (not .DisableNewPullMirrors) (not .DisableNewPushMirrors)}} + {{$onlyNewPushMirrorsEnabled := and (not .DisableNewPushMirrors) .DisableNewPullMirrors}} + {{$onlyNewPullMirrorsEnabled := and .DisableNewPushMirrors (not .DisableNewPullMirrors)}} + {{$existingPushMirror := or .Repository.IsMirror .PushMirrors}} + {{$modifyBrokenPullMirror := and .Repository.IsMirror (not .PullMirror)}} + {{$isWorkingPullMirror := .PullMirror}} + + {{if $showMirrorSettings}}

{{.locale.Tr "repo.settings.mirror_settings"}}

- {{$.locale.Tr "repo.settings.mirror_settings.docs" | Safe}} + {{if $newMirrorsEntirelyEnabled}} + {{$.locale.Tr "repo.settings.mirror_settings.docs"}} + {{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}

+ {{$.locale.Tr "repo.settings.mirror_settings.docs.pull_mirror_instructions"}} + {{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}
+ {{else if $onlyNewPushMirrorsEnabled}} + {{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_pull_mirror.instructions"}} + {{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}
+ {{else if $onlyNewPullMirrorsEnabled}} + {{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_push_mirror.instructions"}} + {{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_push_mirror.pull_mirror_warning"}} + {{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}

+ {{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_push_mirror.info"}} + {{if $existingPushMirror}} + {{$.locale.Tr "repo.settings.mirror_settings.docs.can_still_use"}} + {{end}} + {{else}} + {{$.locale.Tr "repo.settings.mirror_settings.docs.no_new_mirrors"}} {{$.locale.Tr "repo.settings.mirror_settings.docs.can_still_use"}}
+ {{end}} - {{if or .Repository.IsMirror .PushMirrors}} + {{if $existingPushMirror}} @@ -84,7 +114,7 @@ {{end}} - {{if and .Repository.IsMirror (not .PullMirror)}} + {{if $modifyBrokenPullMirror}} {{/* even if a repo is a pull mirror (IsMirror=true), the PullMirror might still be nil if the mirror migration is broken */}} @@ -93,7 +123,7 @@ - {{else if .PullMirror}} + {{else if $isWorkingPullMirror}}
{{$.locale.Tr "repo.settings.mirror_settings.mirrored_repository"}}
{{(MirrorRemoteAddress $.Context .Repository .PullMirror.GetRemoteName false).Address}}