2018-11-29 02:47:09 +05:30
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
2019-04-17 21:36:35 +05:30
|
|
|
"code.gitea.io/gitea/modules/repofiles"
|
2018-11-29 02:47:09 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
// GetTree get the tree of a repository.
|
|
|
|
func GetTree(ctx *context.APIContext) {
|
2019-01-24 23:43:30 +05:30
|
|
|
// 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 23:49:26 +05:30
|
|
|
// - 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
|
|
|
|
// description: number of items per page; default is 1000 or what is set in app.ini as DEFAULT_GIT_TREES_PER_PAGE
|
|
|
|
// required: false
|
|
|
|
// type: integer
|
2019-01-24 23:43:30 +05:30
|
|
|
// responses:
|
|
|
|
// "200":
|
|
|
|
// "$ref": "#/responses/GitTreeResponse"
|
2019-04-17 21:36:35 +05:30
|
|
|
|
|
|
|
sha := ctx.Params(":sha")
|
2018-11-29 02:47:09 +05:30
|
|
|
if len(sha) == 0 {
|
2019-02-06 23:49:26 +05:30
|
|
|
ctx.Error(400, "", "sha not provided")
|
2018-11-29 02:47:09 +05:30
|
|
|
return
|
|
|
|
}
|
2019-04-17 21:36:35 +05:30
|
|
|
if tree, err := repofiles.GetTreeBySHA(ctx.Repo.Repository, sha, ctx.QueryInt("page"), ctx.QueryInt("per_page"), ctx.QueryBool("recursive")); err != nil {
|
|
|
|
ctx.Error(400, "", err.Error())
|
2018-11-29 02:47:09 +05:30
|
|
|
} else {
|
2019-04-17 21:36:35 +05:30
|
|
|
ctx.JSON(200, tree)
|
2018-11-29 02:47:09 +05:30
|
|
|
}
|
|
|
|
}
|