Skip to content

Commit efebb82

Browse files
authored
API: GetReleaseByID return 404 if not found (#12933)
* API: GetReleaseByID return 404 if not found * update swagger docs
1 parent ba20dd7 commit efebb82

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

routers/api/v1/repo/release.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,21 @@ func GetRelease(ctx *context.APIContext) {
4141
// responses:
4242
// "200":
4343
// "$ref": "#/responses/Release"
44+
// "404":
45+
// "$ref": "#/responses/notFound"
4446

4547
id := ctx.ParamsInt64(":id")
4648
release, err := models.GetReleaseByID(id)
47-
if err != nil {
49+
if err != nil && !models.IsErrReleaseNotExist(err) {
4850
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
4951
return
5052
}
51-
if release.RepoID != ctx.Repo.Repository.ID {
53+
if err != nil && models.IsErrReleaseNotExist(err) ||
54+
release.IsTag || release.RepoID != ctx.Repo.Repository.ID {
5255
ctx.NotFound()
5356
return
5457
}
58+
5559
if err := release.LoadAttributes(); err != nil {
5660
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
5761
return
@@ -145,6 +149,8 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) {
145149
// responses:
146150
// "201":
147151
// "$ref": "#/responses/Release"
152+
// "404":
153+
// "$ref": "#/responses/notFound"
148154
// "409":
149155
// "$ref": "#/responses/error"
150156

@@ -235,6 +241,8 @@ func EditRelease(ctx *context.APIContext, form api.EditReleaseOption) {
235241
// responses:
236242
// "200":
237243
// "$ref": "#/responses/Release"
244+
// "404":
245+
// "$ref": "#/responses/notFound"
238246

239247
id := ctx.ParamsInt64(":id")
240248
rel, err := models.GetReleaseByID(id)
@@ -308,6 +316,8 @@ func DeleteRelease(ctx *context.APIContext) {
308316
// responses:
309317
// "204":
310318
// "$ref": "#/responses/empty"
319+
// "404":
320+
// "$ref": "#/responses/notFound"
311321

312322
id := ctx.ParamsInt64(":id")
313323
rel, err := models.GetReleaseByID(id)

templates/swagger/v1_json.tmpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7563,6 +7563,9 @@
75637563
"201": {
75647564
"$ref": "#/responses/Release"
75657565
},
7566+
"404": {
7567+
"$ref": "#/responses/notFound"
7568+
},
75667569
"409": {
75677570
"$ref": "#/responses/error"
75687571
}
@@ -7606,6 +7609,9 @@
76067609
"responses": {
76077610
"200": {
76087611
"$ref": "#/responses/Release"
7612+
},
7613+
"404": {
7614+
"$ref": "#/responses/notFound"
76097615
}
76107616
}
76117617
},
@@ -7642,6 +7648,9 @@
76427648
"responses": {
76437649
"204": {
76447650
"$ref": "#/responses/empty"
7651+
},
7652+
"404": {
7653+
"$ref": "#/responses/notFound"
76457654
}
76467655
}
76477656
},
@@ -7691,6 +7700,9 @@
76917700
"responses": {
76927701
"200": {
76937702
"$ref": "#/responses/Release"
7703+
},
7704+
"404": {
7705+
"$ref": "#/responses/notFound"
76947706
}
76957707
}
76967708
}

0 commit comments

Comments
 (0)