Fixed import order, used type from sdk, removed empty lines
This commit is contained in:
parent
ce09a1c075
commit
3678de006b
|
@ -372,16 +372,12 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
|
||||
m.Group("/repos", func() {
|
||||
m.Get("/search", repo.Search)
|
||||
|
||||
m.Post("/migrate", reqToken(), bind(auth.MigrateRepoForm{}), repo.Migrate)
|
||||
|
||||
m.Group("/:username/:reponame", func() {
|
||||
m.Combo("").Get(repo.Get).Delete(reqToken(), repo.Delete)
|
||||
|
||||
m.Group("/trees", func() {
|
||||
m.Combo("/:sha", context.RepoRef()).Get(repo.GetTree)
|
||||
})
|
||||
|
||||
m.Group("/hooks", func() {
|
||||
m.Combo("").Get(repo.ListHooks).
|
||||
Post(bind(api.CreateHookOption{}), repo.CreateHook)
|
||||
|
@ -392,9 +388,6 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
m.Post("/tests", context.RepoRef(), repo.TestHook)
|
||||
})
|
||||
}, reqToken(), reqRepoWriter())
|
||||
|
||||
|
||||
|
||||
m.Group("/collaborators", func() {
|
||||
m.Get("", repo.ListCollaborators)
|
||||
m.Combo("/:collaborator").Get(repo.IsCollaborator).
|
||||
|
|
|
@ -5,29 +5,15 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"fmt"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/git"
|
||||
"code.gitea.io/sdk/gitea"
|
||||
)
|
||||
|
||||
type TreeEntry struct {
|
||||
Path string `json:"path"`
|
||||
Mode string `json:"mode"`
|
||||
Type string `json:"type"`
|
||||
Size int64 `json:"size,omitempty"`
|
||||
SHA string `json:"sha"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
type Tree struct {
|
||||
SHA string `json:"sha"`
|
||||
URL string `json:"url"`
|
||||
Entries []TreeEntry `json:"tree,omitempty"`
|
||||
Truncated bool `json:"truncated"`
|
||||
}
|
||||
|
||||
func GetTree(ctx *context.APIContext) {
|
||||
sha := ctx.Params("sha")
|
||||
if len(sha) == 0 {
|
||||
|
@ -42,12 +28,12 @@ func GetTree(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
|
||||
func GetTreeBySHA(ctx *context.APIContext, sha string) *Tree {
|
||||
func GetTreeBySHA(ctx *context.APIContext, sha string) *gitea.GitTreeResponse {
|
||||
GitTree, err := ctx.Repo.GitRepo.GetTree(sha)
|
||||
if err != nil || GitTree == nil{
|
||||
return nil
|
||||
}
|
||||
tree := new(Tree)
|
||||
tree := new(gitea.GitTreeResponse)
|
||||
RepoID := strings.TrimRight(setting.AppURL, "/") + "/api/v1/repos/" + ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name
|
||||
tree.SHA = GitTree.ID.String()
|
||||
tree.URL = RepoID + "/trees/" + tree.SHA
|
||||
|
@ -70,9 +56,9 @@ func GetTreeBySHA(ctx *context.APIContext, sha string) *Tree {
|
|||
CopyPos := len(TreeURL) - 40
|
||||
|
||||
if len(Entries) > 1000 {
|
||||
tree.Entries = make([]TreeEntry, 1000)
|
||||
tree.Entries = make([]gitea.GitTreeEntry, 1000)
|
||||
} else {
|
||||
tree.Entries = make([]TreeEntry, len(Entries))
|
||||
tree.Entries = make([]gitea.GitTreeEntry, len(Entries))
|
||||
}
|
||||
for e := range Entries {
|
||||
if e > 1000 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user