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.

68 lines
1.9 KiB

  1. // Copyright 2018 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/modules/context"
  8. "code.gitea.io/gitea/modules/repofiles"
  9. )
  10. // GetTree get the tree of a repository.
  11. func GetTree(ctx *context.APIContext) {
  12. // swagger:operation GET /repos/{owner}/{repo}/git/trees/{sha} repository GetTree
  13. // ---
  14. // summary: Gets the tree of a repository.
  15. // produces:
  16. // - application/json
  17. // parameters:
  18. // - name: owner
  19. // in: path
  20. // description: owner of the repo
  21. // type: string
  22. // required: true
  23. // - name: repo
  24. // in: path
  25. // description: name of the repo
  26. // type: string
  27. // required: true
  28. // - name: sha
  29. // in: path
  30. // description: sha of the commit
  31. // type: string
  32. // required: true
  33. // - name: recursive
  34. // in: query
  35. // description: show all directories and files
  36. // required: false
  37. // type: boolean
  38. // - name: page
  39. // in: query
  40. // description: page number; the 'truncated' field in the response will be true if there are still more items after this page, false if the last page
  41. // required: false
  42. // type: integer
  43. // - name: per_page
  44. // in: query
  45. // description: number of items per page; default is 1000 or what is set in app.ini as DEFAULT_GIT_TREES_PER_PAGE
  46. // required: false
  47. // type: integer
  48. // responses:
  49. // "200":
  50. // "$ref": "#/responses/GitTreeResponse"
  51. // "400":
  52. // "$ref": "#/responses/error"
  53. sha := ctx.Params(":sha")
  54. if len(sha) == 0 {
  55. ctx.Error(http.StatusBadRequest, "", "sha not provided")
  56. return
  57. }
  58. if tree, err := repofiles.GetTreeBySHA(ctx.Repo.Repository, sha, ctx.QueryInt("page"), ctx.QueryInt("per_page"), ctx.QueryBool("recursive")); err != nil {
  59. ctx.Error(http.StatusBadRequest, "", err.Error())
  60. } else {
  61. ctx.JSON(http.StatusOK, tree)
  62. }
  63. }