1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-26 09:09:36 -05:00

Fix 500 when pushing release to an empty repo (#29554) (#29564)

Backport #29554 by @lng2020

As title.
The former code directly used `ctx.Repo.GitRepo`, causing 500.

22b4f0c09f/routers/api/v1/repo/release.go (L241)

Co-authored-by: Nanguan Lin <nanguanlin6@gmail.com>
(cherry picked from commit b84303ef6e73e2436f0c4c3985020be6bbbb5d1e)
This commit is contained in:
Giteabot 2024-03-04 01:10:22 +08:00 committed by Earl Warren
parent ecc0107809
commit b76f370a3f
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -4,6 +4,7 @@
package repo
import (
"fmt"
"net/http"
"code.gitea.io/gitea/models"
@ -221,6 +222,10 @@ func CreateRelease(ctx *context.APIContext) {
// "409":
// "$ref": "#/responses/error"
form := web.GetForm(ctx).(*api.CreateReleaseOption)
if ctx.Repo.Repository.IsEmpty {
ctx.Error(http.StatusUnprocessableEntity, "RepoIsEmpty", fmt.Errorf("repo is empty"))
return
}
rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, form.TagName)
if err != nil {
if !repo_model.IsErrReleaseNotExist(err) {