From 50b4e7f26ea7e24ce193b43144054bff60d08c44 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 18 May 2024 00:07:41 +0800 Subject: [PATCH] Simplify mirror repository API logic (#30963) Fix #30921 (cherry picked from commit 821d2fc2a3cc897f21d707455850177077b72410) --- modules/structs/repo.go | 2 +- routers/api/v1/repo/repo.go | 12 +++--------- templates/swagger/v1_json.tmpl | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/modules/structs/repo.go b/modules/structs/repo.go index 1158160b53..a2e66266af 100644 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -230,7 +230,7 @@ type EditRepoOption struct { Archived *bool `json:"archived,omitempty"` // set to a string like `8h30m0s` to set the mirror interval time MirrorInterval *string `json:"mirror_interval,omitempty"` - // enable prune - remove obsolete remote-tracking references + // enable prune - remove obsolete remote-tracking references when mirroring EnablePrune *bool `json:"enable_prune,omitempty"` } diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 4be8c8ee72..08bc86eed8 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -1072,16 +1072,10 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error { repo := ctx.Repo.Repository - // only update mirror if interval or enable prune are provided - if opts.MirrorInterval == nil && opts.EnablePrune == nil { - return nil - } - - // these values only make sense if the repo is a mirror + // Skip this update if the repo is not a mirror, do not return error. + // Because reporting errors only makes the logic more complex&fragile, it doesn't really help end users. if !repo.IsMirror { - err := fmt.Errorf("repo is not a mirror, can not change mirror interval") - ctx.Error(http.StatusUnprocessableEntity, err.Error(), err) - return err + return nil } // get the mirror from the repo diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 58dfe2b072..67c3f498bf 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -21160,7 +21160,7 @@ "x-go-name": "Description" }, "enable_prune": { - "description": "enable prune - remove obsolete remote-tracking references", + "description": "enable prune - remove obsolete remote-tracking references when mirroring", "type": "boolean", "x-go-name": "EnablePrune" },