From dceaa142a6759f808d02d0aac0d51aafb533affd Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 24 Sep 2020 15:52:02 +0200 Subject: [PATCH 1/2] API: GetReleaseByID return 404 if not found --- routers/api/v1/repo/release.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index e7cc1e8671efa..d6e20d326a483 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -44,14 +44,16 @@ func GetRelease(ctx *context.APIContext) { 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 From d16e4309841149d8d99513e30bca0160b71e5498 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 24 Sep 2020 15:59:57 +0200 Subject: [PATCH 2/2] update swagger docs --- routers/api/v1/repo/release.go | 8 ++++++++ templates/swagger/v1_json.tmpl | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index d6e20d326a483..c2ed1fe024fb0 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -41,6 +41,8 @@ func GetRelease(ctx *context.APIContext) { // responses: // "200": // "$ref": "#/responses/Release" + // "404": + // "$ref": "#/responses/notFound" id := ctx.ParamsInt64(":id") release, err := models.GetReleaseByID(id) @@ -147,6 +149,8 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) { // responses: // "201": // "$ref": "#/responses/Release" + // "404": + // "$ref": "#/responses/notFound" // "409": // "$ref": "#/responses/error" @@ -237,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) @@ -310,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) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 6c0d8c1b329f2..c1847f044026f 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -7563,6 +7563,9 @@ "201": { "$ref": "#/responses/Release" }, + "404": { + "$ref": "#/responses/notFound" + }, "409": { "$ref": "#/responses/error" } @@ -7606,6 +7609,9 @@ "responses": { "200": { "$ref": "#/responses/Release" + }, + "404": { + "$ref": "#/responses/notFound" } } }, @@ -7642,6 +7648,9 @@ "responses": { "204": { "$ref": "#/responses/empty" + }, + "404": { + "$ref": "#/responses/notFound" } } }, @@ -7691,6 +7700,9 @@ "responses": { "200": { "$ref": "#/responses/Release" + }, + "404": { + "$ref": "#/responses/notFound" } } }