Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide 'Mirror Settings' when unneeded, improve hints #24433

Merged
merged 18 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1907,7 +1907,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. <a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/repo-mirror/">How do I mirror repositories?</a>
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_modify = However, you may still modify your settings here.
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
Expand Down
2 changes: 2 additions & 0 deletions routers/web/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
39 changes: 34 additions & 5 deletions templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,43 @@

</div>

{{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)}}
{{$showMirrorSettings := or $newMirrorsPartiallyEnabled .Repository.IsMirror}}
{{$newMirrorsEntirelyEnabled := and (not .DisableNewPullMirrors) (not .DisableNewPushMirrors)}}
{{$onlyNewPushMirrorsEnabled := and (not .DisableNewPushMirrors) .DisableNewPullMirrors}}
{{$onlyNewPullMirrorsEnabled := and .DisableNewPushMirrors (not .DisableNewPullMirrors)}}
{{$modifyExistingPushMirror := or .Repository.IsMirror .PushMirrors}}
{{$modifyBrokenPullMirror := and .Repository.IsMirror (not .PullMirror)}}
{{$isWorkingPullMirror := .PullMirror}}

{{if $showMirrorSettings}}
<h4 class="ui top attached header">
{{.locale.Tr "repo.settings.mirror_settings"}}
</h4>
<div class="ui attached segment">
{{$.locale.Tr "repo.settings.mirror_settings.docs" | Safe}}
{{if $newMirrorsEntirelyEnabled}}
{{$.locale.Tr "repo.settings.mirror_settings.docs"}}
<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/usage/repo-mirror/#pushing-to<ing-to-a-remote-repository">{{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}</a><br><br>
{{$.locale.Tr "repo.settings.mirror_settings.docs.pull_mirror_instructions"}}
<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/usage/repo-mirror/#pulling-from-a-remote-repository">{{$.locale.Tr "repo.settings.mirror_settings.docs.pulling_remote_title"}}</a><br>
{{else if $onlyNewPushMirrorsEnabled}}
{{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_pull_mirror.instructions"}}
<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/usage/repo-mirror/#pushing-to-a-remote-repository">{{$.locale.Tr "settings.mirror_settings.docs.doc_link_title"}}</a>
{{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"}}
<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/usage/repo-mirror/#pulling-from-a-remote-repository">{{$.locale.Tr "repo.settings.mirror_settings.docs.doc_link_title"}}</a><br><br>
{{$.locale.Tr "repo.settings.mirror_settings.docs.disabled_push_mirror.info"}}
{{if $modifyExistingPushMirror}}
{{$.locale.Tr "repo.settings.mirror_settings.docs.can_still_modify"}}
{{end}}
{{else}}
{{$.locale.Tr "repo.settings.mirror_settings.docs.no_new_mirrors"}} {{$.locale.Tr "repo.settings.mirror_settings.docs.can_still_modify"}}
{{end}}
<table class="ui table">
{{if or .Repository.IsMirror .PushMirrors}}
{{if $modifyExistingPushMirror}}
<thead>
<tr>
<th style="width:40%">{{$.locale.Tr "repo.settings.mirror_settings.mirrored_repository"}}</th>
Expand All @@ -84,7 +113,7 @@
</tr>
</thead>
{{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 */}}
<tbody>
<tr>
Expand All @@ -93,7 +122,7 @@
</td>
</tr>
</tbody>
{{else if .PullMirror}}
{{else if $isWorkingPullMirror}}
<tbody>
<tr>
<td>{{(MirrorRemoteAddress $.Context .Repository .PullMirror.GetRemoteName false).Address}}</td>
Expand Down