gitea源码

gitignore.go 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package misc
  4. import (
  5. "net/http"
  6. "code.gitea.io/gitea/modules/options"
  7. repo_module "code.gitea.io/gitea/modules/repository"
  8. "code.gitea.io/gitea/modules/structs"
  9. "code.gitea.io/gitea/modules/util"
  10. "code.gitea.io/gitea/services/context"
  11. )
  12. // Shows a list of all Gitignore templates
  13. func ListGitignoresTemplates(ctx *context.APIContext) {
  14. // swagger:operation GET /gitignore/templates miscellaneous listGitignoresTemplates
  15. // ---
  16. // summary: Returns a list of all gitignore templates
  17. // produces:
  18. // - application/json
  19. // responses:
  20. // "200":
  21. // "$ref": "#/responses/GitignoreTemplateList"
  22. ctx.JSON(http.StatusOK, repo_module.Gitignores)
  23. }
  24. // SHows information about a gitignore template
  25. func GetGitignoreTemplateInfo(ctx *context.APIContext) {
  26. // swagger:operation GET /gitignore/templates/{name} miscellaneous getGitignoreTemplateInfo
  27. // ---
  28. // summary: Returns information about a gitignore template
  29. // produces:
  30. // - application/json
  31. // parameters:
  32. // - name: name
  33. // in: path
  34. // description: name of the template
  35. // type: string
  36. // required: true
  37. // responses:
  38. // "200":
  39. // "$ref": "#/responses/GitignoreTemplateInfo"
  40. // "404":
  41. // "$ref": "#/responses/notFound"
  42. name := util.PathJoinRelX(ctx.PathParam("name"))
  43. text, err := options.Gitignore(name)
  44. if err != nil {
  45. ctx.APIErrorNotFound()
  46. return
  47. }
  48. ctx.JSON(http.StatusOK, &structs.GitignoreTemplateInfo{Name: name, Source: string(text)})
  49. }