You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

release_tags.go 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "net/http"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/context"
  9. "code.gitea.io/gitea/modules/convert"
  10. )
  11. // GetReleaseTag get a single release of a repository by its tagname
  12. func GetReleaseTag(ctx *context.APIContext) {
  13. // swagger:operation GET /repos/{owner}/{repo}/releases/tags/{tag} repository repoGetReleaseTag
  14. // ---
  15. // summary: Get a release by tag name
  16. // produces:
  17. // - application/json
  18. // parameters:
  19. // - name: owner
  20. // in: path
  21. // description: owner of the repo
  22. // type: string
  23. // required: true
  24. // - name: repo
  25. // in: path
  26. // description: name of the repo
  27. // type: string
  28. // required: true
  29. // - name: tag
  30. // in: path
  31. // description: tagname of the release to get
  32. // type: string
  33. // required: true
  34. // responses:
  35. // "200":
  36. // "$ref": "#/responses/Release"
  37. // "404":
  38. // "$ref": "#/responses/notFound"
  39. tag := ctx.Params(":tag")
  40. release, err := models.GetRelease(ctx.Repo.Repository.ID, tag)
  41. if err != nil {
  42. if models.IsErrReleaseNotExist(err) {
  43. ctx.Error(http.StatusNotFound, "GetRelease", err)
  44. return
  45. }
  46. ctx.Error(http.StatusInternalServerError, "GetRelease", err)
  47. return
  48. }
  49. if err := release.LoadAttributes(); err != nil {
  50. ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
  51. return
  52. }
  53. ctx.JSON(http.StatusOK, convert.ToRelease(release))
  54. }