aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorJohan Van de Wauw <johan@gisky.be>2020-09-25 21:11:43 +0200
committerGitHub <noreply@github.com>2020-09-25 20:11:43 +0100
commit34d9cb335c08da785b90acb2c1001b93218f6ac2 (patch)
tree71ad09ed927a79b891b857e97d4e43e506a6763d /routers
parentd71eaacbf2ff9f97c3577ad9e3a9092f0fdab3ec (diff)
downloadgitea-34d9cb335c08da785b90acb2c1001b93218f6ac2.tar.gz
gitea-34d9cb335c08da785b90acb2c1001b93218f6ac2.zip
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>
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/api.go3
-rw-r--r--routers/api/v1/repo/release_tags.go60
2 files changed, 63 insertions, 0 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 3b6f8dbba3..7b2d567e3a 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -797,6 +797,9 @@ func RegisterRoutes(m *macaron.Macaron) {
Delete(reqToken(), reqRepoWriter(models.UnitTypeReleases), repo.DeleteReleaseAttachment)
})
})
+ m.Group("/tags", func() {
+ m.Get("/:tag", repo.GetReleaseTag)
+ })
}, reqRepoReader(models.UnitTypeReleases))
m.Post("/mirror-sync", reqToken(), reqRepoWriter(models.UnitTypeCode), repo.MirrorSync)
m.Get("/editorconfig/:filename", context.RepoRef(), reqRepoReader(models.UnitTypeCode), repo.GetEditorconfig)
diff --git a/routers/api/v1/repo/release_tags.go b/routers/api/v1/repo/release_tags.go
new file mode 100644
index 0000000000..bde3251ba2
--- /dev/null
+++ b/routers/api/v1/repo/release_tags.go
@@ -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())
+}