Skip to content

Commit

Permalink
API: GetReleaseByID return 404 if not found (#12933)
Browse files Browse the repository at this point in the history
* API: GetReleaseByID return 404 if not found

* update swagger docs
  • Loading branch information
6543 authored Sep 24, 2020
1 parent ba20dd7 commit efebb82
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
14 changes: 12 additions & 2 deletions routers/api/v1/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,21 @@ func GetRelease(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Release"
// "404":
// "$ref": "#/responses/notFound"

id := ctx.ParamsInt64(":id")
release, err := models.GetReleaseByID(id)
if err != nil {
if err != nil && !models.IsErrReleaseNotExist(err) {
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
return
}
if release.RepoID != ctx.Repo.Repository.ID {
if err != nil && models.IsErrReleaseNotExist(err) ||
release.IsTag || release.RepoID != ctx.Repo.Repository.ID {
ctx.NotFound()
return
}

if err := release.LoadAttributes(); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
Expand Down Expand Up @@ -145,6 +149,8 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) {
// responses:
// "201":
// "$ref": "#/responses/Release"
// "404":
// "$ref": "#/responses/notFound"
// "409":
// "$ref": "#/responses/error"

Expand Down Expand Up @@ -235,6 +241,8 @@ func EditRelease(ctx *context.APIContext, form api.EditReleaseOption) {
// responses:
// "200":
// "$ref": "#/responses/Release"
// "404":
// "$ref": "#/responses/notFound"

id := ctx.ParamsInt64(":id")
rel, err := models.GetReleaseByID(id)
Expand Down Expand Up @@ -308,6 +316,8 @@ func DeleteRelease(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
// "404":
// "$ref": "#/responses/notFound"

id := ctx.ParamsInt64(":id")
rel, err := models.GetReleaseByID(id)
Expand Down
12 changes: 12 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7563,6 +7563,9 @@
"201": {
"$ref": "#/responses/Release"
},
"404": {
"$ref": "#/responses/notFound"
},
"409": {
"$ref": "#/responses/error"
}
Expand Down Expand Up @@ -7606,6 +7609,9 @@
"responses": {
"200": {
"$ref": "#/responses/Release"
},
"404": {
"$ref": "#/responses/notFound"
}
}
},
Expand Down Expand Up @@ -7642,6 +7648,9 @@
"responses": {
"204": {
"$ref": "#/responses/empty"
},
"404": {
"$ref": "#/responses/notFound"
}
}
},
Expand Down Expand Up @@ -7691,6 +7700,9 @@
"responses": {
"200": {
"$ref": "#/responses/Release"
},
"404": {
"$ref": "#/responses/notFound"
}
}
}
Expand Down

0 comments on commit efebb82

Please sign in to comment.