diff options
author | Peter GardfjÀll <peter.gardfjall.work@gmail.com> | 2022-04-01 20:29:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-01 14:29:57 -0400 |
commit | 43ff92e122550e2d7cc15e23402fc1a7c8e39e88 (patch) | |
tree | 2ed80e7b06041cc7225da0984ab4b8a6809e3d3a /routers/api | |
parent | 4f27c289472a4cfafb5a9b0e38e6a3413c30c562 (diff) | |
download | gitea-43ff92e122550e2d7cc15e23402fc1a7c8e39e88.tar.gz gitea-43ff92e122550e2d7cc15e23402fc1a7c8e39e88.zip |
An attempt to sync a non-mirror repo must give 400 (Bad Request) (#19300)
* An attempt to sync a non-mirror repo must give 400 (Bad Request)
* add missing return statement
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'routers/api')
-rw-r--r-- | routers/api/v1/repo/mirror.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/routers/api/v1/repo/mirror.go b/routers/api/v1/repo/mirror.go index c9ac3e8292..d7facd24d9 100644 --- a/routers/api/v1/repo/mirror.go +++ b/routers/api/v1/repo/mirror.go @@ -5,8 +5,10 @@ package repo import ( + "errors" "net/http" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" @@ -48,6 +50,15 @@ func MirrorSync(ctx *context.APIContext) { return } + if _, err := repo_model.GetMirrorByRepoID(repo.ID); err != nil { + if errors.Is(err, repo_model.ErrMirrorNotExist) { + ctx.Error(http.StatusBadRequest, "MirrorSync", "Repository is not a mirror") + return + } + ctx.Error(http.StatusInternalServerError, "MirrorSync", err) + return + } + mirror_service.StartToMirror(repo.ID) ctx.Status(http.StatusOK) |