88 "errors"
99 "fmt"
1010 "net/http"
11- "strconv"
1211 "strings"
1312 "time"
1413
@@ -298,8 +297,8 @@ func SettingsPost(ctx *context.Context) {
298297 return
299298 }
300299
301- m , err := selectPushMirrorByForm (ctx , form , repo )
302- if err ! = nil {
300+ m , _ , _ := repo_model . GetPushMirrorByIDAndRepoID (ctx , form . PushMirrorID , repo . ID )
301+ if m = = nil {
303302 ctx .NotFound ("" , nil )
304303 return
305304 }
@@ -325,15 +324,13 @@ func SettingsPost(ctx *context.Context) {
325324 return
326325 }
327326
328- id , err := strconv . ParseInt ( form .PushMirrorID , 10 , 64 )
329- if err ! = nil {
330- ctx .ServerError ( "UpdatePushMirrorIntervalPushMirrorID " , err )
327+ m , _ , _ := repo_model . GetPushMirrorByIDAndRepoID ( ctx , form .PushMirrorID , repo . ID )
328+ if m = = nil {
329+ ctx .NotFound ( " " , nil )
331330 return
332331 }
333- m := & repo_model.PushMirror {
334- ID : id ,
335- Interval : interval ,
336- }
332+
333+ m .Interval = interval
337334 if err := repo_model .UpdatePushMirrorInterval (ctx , m ); err != nil {
338335 ctx .ServerError ("UpdatePushMirrorInterval" , err )
339336 return
@@ -342,7 +339,10 @@ func SettingsPost(ctx *context.Context) {
342339 // If we observed its implementation in the context of `push-mirror-sync` where it
343340 // is evident that pushing to the queue is necessary for updates.
344341 // So, there are updates within the given interval, it is necessary to update the queue accordingly.
345- mirror_service .AddPushMirrorToQueue (m .ID )
342+ if ! ctx .FormBool ("push_mirror_defer_sync" ) {
343+ // push_mirror_defer_sync is mainly for testing purpose, we do not really want to sync the push mirror immediately
344+ mirror_service .AddPushMirrorToQueue (m .ID )
345+ }
346346 ctx .Flash .Success (ctx .Tr ("repo.settings.update_settings_success" ))
347347 ctx .Redirect (repo .Link () + "/settings" )
348348
@@ -356,18 +356,18 @@ func SettingsPost(ctx *context.Context) {
356356 // as an error on the UI for this action
357357 ctx .Data ["Err_RepoName" ] = nil
358358
359- m , err := selectPushMirrorByForm (ctx , form , repo )
360- if err ! = nil {
359+ m , _ , _ := repo_model . GetPushMirrorByIDAndRepoID (ctx , form . PushMirrorID , repo . ID )
360+ if m = = nil {
361361 ctx .NotFound ("" , nil )
362362 return
363363 }
364364
365- if err = mirror_service .RemovePushMirrorRemote (ctx , m ); err != nil {
365+ if err : = mirror_service .RemovePushMirrorRemote (ctx , m ); err != nil {
366366 ctx .ServerError ("RemovePushMirrorRemote" , err )
367367 return
368368 }
369369
370- if err = repo_model .DeletePushMirrors (ctx , repo_model.PushMirrorOptions {ID : m .ID , RepoID : m .RepoID }); err != nil {
370+ if err : = repo_model .DeletePushMirrors (ctx , repo_model.PushMirrorOptions {ID : m .ID , RepoID : m .RepoID }); err != nil {
371371 ctx .ServerError ("DeletePushMirrorByID" , err )
372372 return
373373 }
@@ -970,24 +970,3 @@ func handleSettingRemoteAddrError(ctx *context.Context, err error, form *forms.R
970970 }
971971 ctx .RenderWithErr (ctx .Tr ("repo.mirror_address_url_invalid" ), tplSettingsOptions , form )
972972}
973-
974- func selectPushMirrorByForm (ctx * context.Context , form * forms.RepoSettingForm , repo * repo_model.Repository ) (* repo_model.PushMirror , error ) {
975- id , err := strconv .ParseInt (form .PushMirrorID , 10 , 64 )
976- if err != nil {
977- return nil , err
978- }
979-
980- pushMirrors , _ , err := repo_model .GetPushMirrorsByRepoID (ctx , repo .ID , db.ListOptions {})
981- if err != nil {
982- return nil , err
983- }
984-
985- for _ , m := range pushMirrors {
986- if m .ID == id {
987- m .Repo = repo
988- return m , nil
989- }
990- }
991-
992- return nil , fmt .Errorf ("PushMirror[%v] not associated to repository %v" , id , repo )
993- }
0 commit comments