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.

tag.go 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2019 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. "code.gitea.io/gitea/modules/context"
  7. "code.gitea.io/gitea/routers/api/v1/convert"
  8. "net/http"
  9. api "code.gitea.io/gitea/modules/structs"
  10. )
  11. // ListTags list all the tags of a repository
  12. func ListTags(ctx *context.APIContext) {
  13. // swagger:operation GET /repos/{owner}/{repo}/tags repository repoListTags
  14. // ---
  15. // summary: List a repository's tags
  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. // responses:
  30. // "200":
  31. // "$ref": "#/responses/TagList"
  32. tags, err := ctx.Repo.GitRepo.GetTagInfos()
  33. if err != nil {
  34. ctx.Error(500, "GetTags", err)
  35. return
  36. }
  37. apiTags := make([]*api.Tag, len(tags))
  38. for i := range tags {
  39. apiTags[i] = convert.ToTag(ctx.Repo.Repository, tags[i])
  40. }
  41. ctx.JSON(200, &apiTags)
  42. }
  43. // GetTag get the tag of a repository.
  44. func GetTag(ctx *context.APIContext) {
  45. // swagger:operation GET /repos/{owner}/{repo}/git/tags/{sha} repository GetTag
  46. // ---
  47. // summary: Gets the tag of a repository.
  48. // produces:
  49. // - application/json
  50. // parameters:
  51. // - name: owner
  52. // in: path
  53. // description: owner of the repo
  54. // type: string
  55. // required: true
  56. // - name: repo
  57. // in: path
  58. // description: name of the repo
  59. // type: string
  60. // required: true
  61. // - name: sha
  62. // in: path
  63. // description: sha of the tag
  64. // type: string
  65. // required: true
  66. // responses:
  67. // "200":
  68. // "$ref": "#/responses/AnnotatedTag"
  69. sha := ctx.Params("sha")
  70. if len(sha) == 0 {
  71. ctx.Error(http.StatusBadRequest, "", "SHA not provided")
  72. return
  73. }
  74. if tag, err := ctx.Repo.GitRepo.GetAnnotatedTag(sha); err != nil {
  75. ctx.Error(http.StatusBadRequest, "GetTag", err)
  76. } else {
  77. commit, err := tag.Commit()
  78. if err != nil {
  79. ctx.Error(http.StatusBadRequest, "GetTag", err)
  80. }
  81. ctx.JSON(http.StatusOK, convert.ToAnnotatedTag(ctx.Repo.Repository, tag, commit))
  82. }
  83. }