diff options
author | Giteabot <teabot@gitea.io> | 2024-05-18 16:26:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-18 08:26:20 +0000 |
commit | 8eac16de217978c1f7034f8e360f54d8d638e95e (patch) | |
tree | d9b8948329bffbe479f50833f9a2cba7027b6181 | |
parent | bd3787c774adbbb0c7df834f5d4615dc795e7f6c (diff) | |
download | gitea-8eac16de217978c1f7034f8e360f54d8d638e95e.tar.gz gitea-8eac16de217978c1f7034f8e360f54d8d638e95e.zip |
Simplify mirror repository API logic (#30963) (#31009)
Backport #30963 by wxiaoguang
Fix #30921
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
-rw-r--r-- | modules/structs/repo.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 12 | ||||
-rw-r--r-- | 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 bc8eb0b756..1fe826cf89 100644 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -217,7 +217,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 7f35a7fe41..e759142938 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -1062,16 +1062,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 1c23c72ac2..764a13063d 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -20610,7 +20610,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" }, |