Skip to content

Commit ab388de

Browse files
puni9869wxiaoguang
andauthored
Allow editing push mirrors after creation (#26151)
Allow users to edit the sync interval for existing push mirrors. Currently, there is no way to modify the interval once the mirror is created. <details> <summary>Screenshots</summary> ## Before <img width="936" alt="Screenshot 2023-07-26 at 9 31 21 AM" src="https://github.com/go-gitea/gitea/assets/80308335/35b8a40c-4320-474c-a866-1dea0f1fa0de"> ## After <img width="945" alt="Screenshot 2023-07-26 at 9 44 40 AM" src="https://github.com/go-gitea/gitea/assets/80308335/ee12e12f-0f68-4feb-90eb-33366f5997d3"> ### On hover <img width="247" alt="image" src="https://github.com/go-gitea/gitea/assets/80308335/2f32de45-bd50-4150-9623-3be2ef3ea7f8"> <img width="237" alt="image" src="https://github.com/go-gitea/gitea/assets/80308335/49f4ab4d-ccff-4489-80ce-a9788a73c3bb"> <img width="245" alt="image" src="https://github.com/go-gitea/gitea/assets/80308335/165fc888-9d48-438a-b730-d4beb12122af"> ### Edit modal <img width="905" alt="image" src="https://github.com/go-gitea/gitea/assets/80308335/2a7ca24b-4f36-4e0e-9799-39f2ecc46413"> ### Only valid times are allowed <img width="728" alt="Screenshot 2023-07-26 at 9 50 01 AM" src="https://github.com/go-gitea/gitea/assets/80308335/ced6d330-c235-4e29-8f17-28daddcf1444"> <img width="853" alt="image" src="https://github.com/go-gitea/gitea/assets/80308335/8636f62a-70d1-4684-a3e8-b205adc03580"> </details> Fixes #21295 --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent ab0e588 commit ab388de

File tree

5 files changed

+93
-4
lines changed

5 files changed

+93
-4
lines changed

models/repo/pushmirror.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ func UpdatePushMirror(ctx context.Context, m *PushMirror) error {
8585
return err
8686
}
8787

88+
// UpdatePushMirrorInterval updates the push-mirror
89+
func UpdatePushMirrorInterval(ctx context.Context, m *PushMirror) error {
90+
_, err := db.GetEngine(ctx).ID(m.ID).Cols("interval").Update(m)
91+
return err
92+
}
93+
8894
func DeletePushMirrors(ctx context.Context, opts PushMirrorOptions) error {
8995
if opts.RepoID > 0 {
9096
_, err := db.GetEngine(ctx).Where(opts.toConds()).Delete(&PushMirror{})

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,8 @@ settings.mirror_settings.last_update = Last update
19661966
settings.mirror_settings.push_mirror.none = No push mirrors configured
19671967
settings.mirror_settings.push_mirror.remote_url = Git Remote Repository URL
19681968
settings.mirror_settings.push_mirror.add = Add Push Mirror
1969+
settings.mirror_settings.push_mirror.edit_sync_time = Edit mirror sync interval
1970+
19691971
settings.sync_mirror = Synchronize Now
19701972
settings.mirror_sync_in_progress = Mirror synchronization is in progress. Check back in a minute.
19711973
settings.site = Website

routers/web/repo/setting/setting.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,43 @@ func SettingsPost(ctx *context.Context) {
299299
ctx.Flash.Info(ctx.Tr("repo.settings.mirror_sync_in_progress"))
300300
ctx.Redirect(repo.Link() + "/settings")
301301

302+
case "push-mirror-update":
303+
if !setting.Mirror.Enabled {
304+
ctx.NotFound("", nil)
305+
return
306+
}
307+
308+
// This section doesn't require repo_name/RepoName to be set in the form, don't show it
309+
// as an error on the UI for this action
310+
ctx.Data["Err_RepoName"] = nil
311+
312+
interval, err := time.ParseDuration(form.PushMirrorInterval)
313+
if err != nil || (interval != 0 && interval < setting.Mirror.MinInterval) {
314+
ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &forms.RepoSettingForm{})
315+
return
316+
}
317+
318+
id, err := strconv.ParseInt(form.PushMirrorID, 10, 64)
319+
if err != nil {
320+
ctx.ServerError("UpdatePushMirrorIntervalPushMirrorID", err)
321+
return
322+
}
323+
m := &repo_model.PushMirror{
324+
ID: id,
325+
Interval: interval,
326+
}
327+
if err := repo_model.UpdatePushMirrorInterval(ctx, m); err != nil {
328+
ctx.ServerError("UpdatePushMirrorInterval", err)
329+
return
330+
}
331+
// Background why we are adding it to Queue
332+
// If we observed its implementation in the context of `push-mirror-sync` where it
333+
// is evident that pushing to the queue is necessary for updates.
334+
// So, there are updates within the given interval, it is necessary to update the queue accordingly.
335+
mirror_module.AddPushMirrorToQueue(m.ID)
336+
ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success"))
337+
ctx.Redirect(repo.Link() + "/settings")
338+
302339
case "push-mirror-remove":
303340
if !setting.Mirror.Enabled {
304341
ctx.NotFound("", nil)

templates/repo/settings/options.tmpl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,27 @@
203203
<td>{{$.locale.Tr "repo.settings.mirror_settings.direction.push"}}</td>
204204
<td>{{if .LastUpdateUnix}}{{DateTime "full" .LastUpdateUnix}}{{else}}{{$.locale.Tr "never"}}{{end}} {{if .LastError}}<div class="ui red label" data-tooltip-content="{{.LastError}}">{{$.locale.Tr "error"}}</div>{{end}}</td>
205205
<td class="right aligned">
206+
<button
207+
class="ui tiny button show-modal"
208+
data-modal="#push-mirror-edit-modal"
209+
data-tooltip-content="{{$.locale.Tr "repo.settings.mirror_settings.push_mirror.edit_sync_time"}}"
210+
data-modal-push-mirror-edit-id="{{.ID}}"
211+
data-modal-push-mirror-edit-interval="{{.Interval}}"
212+
data-modal-push-mirror-edit-address="{{$address.Address}}"
213+
>
214+
{{svg "octicon-pencil" 14}}
215+
</button>
206216
<form method="post" class="gt-dib">
207217
{{$.CsrfTokenHtml}}
208-
<input type="hidden" name="action" value="push-mirror-remove">
218+
<input type="hidden" name="action" value="push-mirror-sync">
209219
<input type="hidden" name="push_mirror_id" value="{{.ID}}">
210-
<button class="ui basic red tiny button inline text-thin">{{$.locale.Tr "remove"}}</button>
220+
<button class="ui primary tiny button" data-tooltip-content="{{$.locale.Tr "repo.settings.sync_mirror"}}">{{svg "octicon-sync" 14}}</button>
211221
</form>
212222
<form method="post" class="gt-dib">
213223
{{$.CsrfTokenHtml}}
214-
<input type="hidden" name="action" value="push-mirror-sync">
224+
<input type="hidden" name="action" value="push-mirror-remove">
215225
<input type="hidden" name="push_mirror_id" value="{{.ID}}">
216-
<button class="ui primary tiny button inline text-thin">{{$.locale.Tr "repo.settings.sync_mirror"}}</button>
226+
<button class="ui basic red tiny button" data-tooltip-content="{{$.locale.Tr "remove"}}">{{svg "octicon-trash" 14}}</button>
217227
</form>
218228
</td>
219229
</tr>
@@ -980,3 +990,5 @@
980990
</div>
981991
{{end}}
982992
{{end}}
993+
994+
{{template "repo/settings/push_mirror_sync_modal" .}}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<div class="ui small modal" id="push-mirror-edit-modal">
2+
<div class="header">
3+
{{$.locale.Tr "repo.settings.mirror_settings.push_mirror.edit_sync_time"}}
4+
</div>
5+
<div class="content">
6+
<form class="ui form ignore-dirty" method="post">
7+
{{.CsrfTokenHtml}}
8+
<input type="hidden" name="action" value="push-mirror-update">
9+
<input type="hidden" name="push_mirror_id" id="push-mirror-edit-id">
10+
<div class="field">
11+
<label for="name">{{$.locale.Tr "repo.settings.mirror_settings.mirrored_repository"}}</label>
12+
<div class="ui small input">
13+
<input id="push-mirror-edit-address" readonly>
14+
</div>
15+
</div>
16+
<div class="inline field">
17+
<label for="push-mirror-edit-interval">{{.locale.Tr "repo.mirror_interval" .MinimumMirrorInterval}}</label>
18+
<input id="push-mirror-edit-interval" name="push_mirror_interval" autofocus>
19+
</div>
20+
<div class="actions">
21+
<button class="ui small basic cancel button">
22+
{{svg "octicon-x"}}
23+
{{.locale.Tr "cancel"}}
24+
</button>
25+
<button class="ui primary small approve button">
26+
{{svg "fontawesome-save"}}
27+
{{.locale.Tr "save"}}
28+
</button>
29+
</div>
30+
</form>
31+
</div>
32+
</div>

0 commit comments

Comments
 (0)