mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-27 13:39:19 -05:00
Simplify mirror repository API logic (#30963)
Fix #30921
(cherry picked from commit 821d2fc2a3cc897f21d707455850177077b72410)
(cherry picked from commit 50b4e7f26e
)
Equivalent to the Gitea v1.22 commit
(cherry picked from commit 8eac16de217978c1f7034f8e360f54d8d638e95e)
This commit is contained in:
parent
50ef4ecefe
commit
1fd1100ac9
3 changed files with 5 additions and 11 deletions
|
@ -227,7 +227,7 @@ type EditRepoOption struct {
|
||||||
Archived *bool `json:"archived,omitempty"`
|
Archived *bool `json:"archived,omitempty"`
|
||||||
// set to a string like `8h30m0s` to set the mirror interval time
|
// set to a string like `8h30m0s` to set the mirror interval time
|
||||||
MirrorInterval *string `json:"mirror_interval,omitempty"`
|
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"`
|
EnablePrune *bool `json:"enable_prune,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1054,16 +1054,10 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e
|
||||||
func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error {
|
func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||||
repo := ctx.Repo.Repository
|
repo := ctx.Repo.Repository
|
||||||
|
|
||||||
// only update mirror if interval or enable prune are provided
|
// Skip this update if the repo is not a mirror, do not return error.
|
||||||
if opts.MirrorInterval == nil && opts.EnablePrune == nil {
|
// Because reporting errors only makes the logic more complex&fragile, it doesn't really help end users.
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// these values only make sense if the repo is a mirror
|
|
||||||
if !repo.IsMirror {
|
if !repo.IsMirror {
|
||||||
err := fmt.Errorf("repo is not a mirror, can not change mirror interval")
|
return nil
|
||||||
ctx.Error(http.StatusUnprocessableEntity, err.Error(), err)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the mirror from the repo
|
// get the mirror from the repo
|
||||||
|
|
2
templates/swagger/v1_json.tmpl
generated
2
templates/swagger/v1_json.tmpl
generated
|
@ -20115,7 +20115,7 @@
|
||||||
"x-go-name": "Description"
|
"x-go-name": "Description"
|
||||||
},
|
},
|
||||||
"enable_prune": {
|
"enable_prune": {
|
||||||
"description": "enable prune - remove obsolete remote-tracking references",
|
"description": "enable prune - remove obsolete remote-tracking references when mirroring",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"x-go-name": "EnablePrune"
|
"x-go-name": "EnablePrune"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue