gitea源码

label_templates.go 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package misc
  4. import (
  5. "net/http"
  6. repo_module "code.gitea.io/gitea/modules/repository"
  7. "code.gitea.io/gitea/modules/util"
  8. "code.gitea.io/gitea/services/context"
  9. "code.gitea.io/gitea/services/convert"
  10. )
  11. // Shows a list of all Label templates
  12. func ListLabelTemplates(ctx *context.APIContext) {
  13. // swagger:operation GET /label/templates miscellaneous listLabelTemplates
  14. // ---
  15. // summary: Returns a list of all label templates
  16. // produces:
  17. // - application/json
  18. // responses:
  19. // "200":
  20. // "$ref": "#/responses/LabelTemplateList"
  21. result := make([]string, len(repo_module.LabelTemplateFiles))
  22. for i := range repo_module.LabelTemplateFiles {
  23. result[i] = repo_module.LabelTemplateFiles[i].DisplayName
  24. }
  25. ctx.JSON(http.StatusOK, result)
  26. }
  27. // Shows all labels in a template
  28. func GetLabelTemplate(ctx *context.APIContext) {
  29. // swagger:operation GET /label/templates/{name} miscellaneous getLabelTemplateInfo
  30. // ---
  31. // summary: Returns all labels in a template
  32. // produces:
  33. // - application/json
  34. // parameters:
  35. // - name: name
  36. // in: path
  37. // description: name of the template
  38. // type: string
  39. // required: true
  40. // responses:
  41. // "200":
  42. // "$ref": "#/responses/LabelTemplateInfo"
  43. // "404":
  44. // "$ref": "#/responses/notFound"
  45. name := util.PathJoinRelX(ctx.PathParam("name"))
  46. labels, err := repo_module.LoadTemplateLabelsByDisplayName(name)
  47. if err != nil {
  48. ctx.APIErrorNotFound()
  49. return
  50. }
  51. ctx.JSON(http.StatusOK, convert.ToLabelTemplateList(labels))
  52. }