Skip to content

Commit 6e2aafd

Browse files
authored
Fix 500 when pushing release to an empty repo (#29554)
As title. The former code directly used `ctx.Repo.GitRepo`, causing 500. https://github.com/go-gitea/gitea/blob/22b4f0c09f1de5e581929bd10f39833d30d2c482/routers/api/v1/repo/release.go#L241
1 parent efa631a commit 6e2aafd

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

routers/api/v1/repo/release.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package repo
55

66
import (
7+
"fmt"
78
"net/http"
89

910
"code.gitea.io/gitea/models"
@@ -215,6 +216,10 @@ func CreateRelease(ctx *context.APIContext) {
215216
// "409":
216217
// "$ref": "#/responses/error"
217218
form := web.GetForm(ctx).(*api.CreateReleaseOption)
219+
if ctx.Repo.Repository.IsEmpty {
220+
ctx.Error(http.StatusUnprocessableEntity, "RepoIsEmpty", fmt.Errorf("repo is empty"))
221+
return
222+
}
218223
rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, form.TagName)
219224
if err != nil {
220225
if !repo_model.IsErrReleaseNotExist(err) {

0 commit comments

Comments
 (0)