2018-11-28 22:17:09 +01:00
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2018-11-28 22:17:09 +01:00
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
2019-12-20 18:07:12 +01:00
|
|
|
"net/http"
|
|
|
|
|
2024-02-27 08:12:22 +01:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2021-11-24 08:56:24 +01:00
|
|
|
files_service "code.gitea.io/gitea/services/repository/files"
|
2018-11-28 22:17:09 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetTree get the tree of a repository.
|
|
|
|
func GetTree(ctx *context.APIContext) {
|
2019-01-24 19:13:30 +01:00
|
|
|
// swagger:operation GET /repos/{owner}/{repo}/git/trees/{sha} repository GetTree
|
|
|
|
// ---
|
|
|
|
// summary: Gets the tree of a repository.
|
|
|
|
// produces:
|
|
|
|
// - application/json
|
|
|
|
// parameters:
|
|
|
|
// - name: owner
|
|
|
|
// in: path
|
|
|
|
// description: owner of the repo
|
|
|
|
// type: string
|
|
|
|
// required: true
|
|
|
|
// - name: repo
|
|
|
|
// in: path
|
|
|
|
// description: name of the repo
|
|
|
|
// type: string
|
|
|
|
// required: true
|
|
|
|
// - name: sha
|
|
|
|
// in: path
|
|
|
|
// description: sha of the commit
|
|
|
|
// type: string
|
|
|
|
// required: true
|
2019-02-06 19:19:26 +01:00
|
|
|
// - name: recursive
|
|
|
|
// in: query
|
|
|
|
// description: show all directories and files
|
|
|
|
// required: false
|
|
|
|
// type: boolean
|
|
|
|
// - name: page
|
|
|
|
// in: query
|
|
|
|
// 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
|
|
|
|
// required: false
|
|
|
|
// type: integer
|
|
|
|
// - name: per_page
|
|
|
|
// in: query
|
2020-06-09 06:57:38 +02:00
|
|
|
// description: number of items per page
|
2019-02-06 19:19:26 +01:00
|
|
|
// required: false
|
|
|
|
// type: integer
|
2019-01-24 19:13:30 +01:00
|
|
|
// responses:
|
|
|
|
// "200":
|
|
|
|
// "$ref": "#/responses/GitTreeResponse"
|
2019-12-20 18:07:12 +01:00
|
|
|
// "400":
|
|
|
|
// "$ref": "#/responses/error"
|
2023-09-13 04:37:54 +02:00
|
|
|
// "404":
|
|
|
|
// "$ref": "#/responses/notFound"
|
2019-04-17 18:06:35 +02:00
|
|
|
|
|
|
|
sha := ctx.Params(":sha")
|
2018-11-28 22:17:09 +01:00
|
|
|
if len(sha) == 0 {
|
2019-12-20 18:07:12 +01:00
|
|
|
ctx.Error(http.StatusBadRequest, "", "sha not provided")
|
2018-11-28 22:17:09 +01:00
|
|
|
return
|
|
|
|
}
|
2022-01-20 00:26:57 +01:00
|
|
|
if tree, err := files_service.GetTreeBySHA(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, sha, ctx.FormInt("page"), ctx.FormInt("per_page"), ctx.FormBool("recursive")); err != nil {
|
2019-12-20 18:07:12 +01:00
|
|
|
ctx.Error(http.StatusBadRequest, "", err.Error())
|
2018-11-28 22:17:09 +01:00
|
|
|
} else {
|
2021-12-15 06:39:34 +01:00
|
|
|
ctx.SetTotalCountHeader(int64(tree.TotalCount))
|
2019-12-20 18:07:12 +01:00
|
|
|
ctx.JSON(http.StatusOK, tree)
|
2018-11-28 22:17:09 +01:00
|
|
|
}
|
|
|
|
}
|