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.

tree.go 1.8KB

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