88 "errors"
99 "fmt"
1010 "net/http"
11- "strconv"
1211 "strings"
1312 "time"
1413
@@ -290,8 +289,8 @@ func SettingsPost(ctx *context.Context) {
290289 return
291290 }
292291
293- m , err := selectPushMirrorByForm (ctx , form , repo )
294- if err ! = nil {
292+ m , _ , _ := repo_model . GetPushMirrorByIDAndRepoID (ctx , form . PushMirrorID , repo . ID )
293+ if m = = nil {
295294 ctx .NotFound ("" , nil )
296295 return
297296 }
@@ -317,8 +316,8 @@ func SettingsPost(ctx *context.Context) {
317316 return
318317 }
319318
320- m , err := selectPushMirrorByForm (ctx , form , repo )
321- if err ! = nil {
319+ m , _ , _ := repo_model . GetPushMirrorByIDAndRepoID (ctx , form . PushMirrorID , repo . ID )
320+ if m = = nil {
322321 ctx .NotFound ("" , nil )
323322 return
324323 }
@@ -332,7 +331,10 @@ func SettingsPost(ctx *context.Context) {
332331 // If we observed its implementation in the context of `push-mirror-sync` where it
333332 // is evident that pushing to the queue is necessary for updates.
334333 // So, there are updates within the given interval, it is necessary to update the queue accordingly.
335- mirror_service .AddPushMirrorToQueue (m .ID )
334+ if ! ctx .FormBool ("push_mirror_defer_sync" ) {
335+ // push_mirror_defer_sync is mainly for testing purpose, we do not really want to sync the push mirror immediately
336+ mirror_service .AddPushMirrorToQueue (m .ID )
337+ }
336338 ctx .Flash .Success (ctx .Tr ("repo.settings.update_settings_success" ))
337339 ctx .Redirect (repo .Link () + "/settings" )
338340
@@ -346,18 +348,18 @@ func SettingsPost(ctx *context.Context) {
346348 // as an error on the UI for this action
347349 ctx .Data ["Err_RepoName" ] = nil
348350
349- m , err := selectPushMirrorByForm (ctx , form , repo )
350- if err ! = nil {
351+ m , _ , _ := repo_model . GetPushMirrorByIDAndRepoID (ctx , form . PushMirrorID , repo . ID )
352+ if m = = nil {
351353 ctx .NotFound ("" , nil )
352354 return
353355 }
354356
355- if err = mirror_service .RemovePushMirrorRemote (ctx , m ); err != nil {
357+ if err : = mirror_service .RemovePushMirrorRemote (ctx , m ); err != nil {
356358 ctx .ServerError ("RemovePushMirrorRemote" , err )
357359 return
358360 }
359361
360- if err = repo_model .DeletePushMirrors (ctx , repo_model.PushMirrorOptions {ID : m .ID , RepoID : m .RepoID }); err != nil {
362+ if err : = repo_model .DeletePushMirrors (ctx , repo_model.PushMirrorOptions {ID : m .ID , RepoID : m .RepoID }); err != nil {
361363 ctx .ServerError ("DeletePushMirrorByID" , err )
362364 return
363365 }
@@ -993,21 +995,3 @@ func handleSettingRemoteAddrError(ctx *context.Context, err error, form *forms.R
993995 }
994996 ctx .RenderWithErr (ctx .Tr ("repo.mirror_address_url_invalid" ), tplSettingsOptions , form )
995997}
996-
997- func selectPushMirrorByForm (ctx * context.Context , form * forms.RepoSettingForm , repo * repo_model.Repository ) (* repo_model.PushMirror , error ) {
998- id , err := strconv .ParseInt (form .PushMirrorID , 10 , 64 )
999- if err != nil {
1000- return nil , err
1001- }
1002-
1003- pushMirror , err := repo_model .GetPushMirrorByIDAndRepoID (ctx , id , repo .ID )
1004- if err != nil {
1005- if err == repo_model .ErrPushMirrorNotExist {
1006- return nil , fmt .Errorf ("PushMirror[%v] not associated to repository %v" , id , repo )
1007- }
1008- return nil , err
1009- }
1010-
1011- pushMirror .Repo = repo
1012- return pushMirror , nil
1013- }
0 commit comments