Skip to content

Commit 821d2fc

Browse files
authored
Simplify mirror repository API logic (go-gitea#30963)
Fix go-gitea#30921
1 parent 68d5c18 commit 821d2fc

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

modules/structs/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ type EditRepoOption struct {
217217
Archived *bool `json:"archived,omitempty"`
218218
// set to a string like `8h30m0s` to set the mirror interval time
219219
MirrorInterval *string `json:"mirror_interval,omitempty"`
220-
// enable prune - remove obsolete remote-tracking references
220+
// enable prune - remove obsolete remote-tracking references when mirroring
221221
EnablePrune *bool `json:"enable_prune,omitempty"`
222222
}
223223

routers/api/v1/repo/repo.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,16 +1062,10 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e
10621062
func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error {
10631063
repo := ctx.Repo.Repository
10641064

1065-
// only update mirror if interval or enable prune are provided
1066-
if opts.MirrorInterval == nil && opts.EnablePrune == nil {
1067-
return nil
1068-
}
1069-
1070-
// these values only make sense if the repo is a mirror
1065+
// Skip this update if the repo is not a mirror, do not return error.
1066+
// Because reporting errors only makes the logic more complex&fragile, it doesn't really help end users.
10711067
if !repo.IsMirror {
1072-
err := fmt.Errorf("repo is not a mirror, can not change mirror interval")
1073-
ctx.Error(http.StatusUnprocessableEntity, err.Error(), err)
1074-
return err
1068+
return nil
10751069
}
10761070

10771071
// get the mirror from the repo

templates/swagger/v1_json.tmpl

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)