API: Get release by tags endpoint (#12932)
Get a release based on a tag name (for which a release exists). Based on: https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name Co-authored-by: 赵智超 <1012112796@qq.com> Co-authored-by: 6543 <6543@obermui.de>tokarchuk/v1.17
parent
d71eaacbf2
commit
34d9cb335c
@ -0,0 +1,60 @@ |
||||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package repo |
||||
|
||||
import ( |
||||
"net/http" |
||||
|
||||
"code.gitea.io/gitea/models" |
||||
"code.gitea.io/gitea/modules/context" |
||||
) |
||||
|
||||
// GetReleaseTag get a single release of a repository by its tagname
|
||||
func GetReleaseTag(ctx *context.APIContext) { |
||||
// swagger:operation GET /repos/{owner}/{repo}/releases/tags/{tag} repository repoGetReleaseTag
|
||||
// ---
|
||||
// summary: Get a release by tag name
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
// in: path
|
||||
// description: name of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: tag
|
||||
// in: path
|
||||
// description: tagname of the release to get
|
||||
// type: string
|
||||
// required: true
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/Release"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
tag := ctx.Params(":tag") |
||||
|
||||
release, err := models.GetRelease(ctx.Repo.Repository.ID, tag) |
||||
if err != nil { |
||||
if models.IsErrReleaseNotExist(err) { |
||||
ctx.Error(http.StatusNotFound, "GetRelease", err) |
||||
return |
||||
} |
||||
ctx.Error(http.StatusInternalServerError, "GetRelease", err) |
||||
return |
||||
} |
||||
|
||||
if err := release.LoadAttributes(); err != nil { |
||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err) |
||||
return |
||||
} |
||||
ctx.JSON(http.StatusOK, release.APIFormat()) |
||||
} |
Loading…
Reference in new issue