Fixed import order, used type from sdk, removed empty lines

This commit is contained in:
Kasi 2018-06-13 11:04:39 +01:00
parent ce09a1c075
commit 3678de006b
2 changed files with 8 additions and 29 deletions

View File

@ -372,16 +372,12 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/repos", func() { m.Group("/repos", func() {
m.Get("/search", repo.Search) m.Get("/search", repo.Search)
m.Post("/migrate", reqToken(), bind(auth.MigrateRepoForm{}), repo.Migrate) m.Post("/migrate", reqToken(), bind(auth.MigrateRepoForm{}), repo.Migrate)
m.Group("/:username/:reponame", func() { m.Group("/:username/:reponame", func() {
m.Combo("").Get(repo.Get).Delete(reqToken(), repo.Delete) m.Combo("").Get(repo.Get).Delete(reqToken(), repo.Delete)
m.Group("/trees", func() { m.Group("/trees", func() {
m.Combo("/:sha", context.RepoRef()).Get(repo.GetTree) m.Combo("/:sha", context.RepoRef()).Get(repo.GetTree)
}) })
m.Group("/hooks", func() { m.Group("/hooks", func() {
m.Combo("").Get(repo.ListHooks). m.Combo("").Get(repo.ListHooks).
Post(bind(api.CreateHookOption{}), repo.CreateHook) Post(bind(api.CreateHookOption{}), repo.CreateHook)
@ -392,9 +388,6 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/tests", context.RepoRef(), repo.TestHook) m.Post("/tests", context.RepoRef(), repo.TestHook)
}) })
}, reqToken(), reqRepoWriter()) }, reqToken(), reqRepoWriter())
m.Group("/collaborators", func() { m.Group("/collaborators", func() {
m.Get("", repo.ListCollaborators) m.Get("", repo.ListCollaborators)
m.Combo("/:collaborator").Get(repo.IsCollaborator). m.Combo("/:collaborator").Get(repo.IsCollaborator).

View File

@ -5,29 +5,15 @@
package repo package repo
import ( import (
"code.gitea.io/gitea/modules/context"
"fmt" "fmt"
"code.gitea.io/gitea/modules/setting"
"strings" "strings"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/git" "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) { func GetTree(ctx *context.APIContext) {
sha := ctx.Params("sha") sha := ctx.Params("sha")
if len(sha) == 0 { 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) GitTree, err := ctx.Repo.GitRepo.GetTree(sha)
if err != nil || GitTree == nil{ if err != nil || GitTree == nil{
return 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 RepoID := strings.TrimRight(setting.AppURL, "/") + "/api/v1/repos/" + ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name
tree.SHA = GitTree.ID.String() tree.SHA = GitTree.ID.String()
tree.URL = RepoID + "/trees/" + tree.SHA tree.URL = RepoID + "/trees/" + tree.SHA
@ -70,9 +56,9 @@ func GetTreeBySHA(ctx *context.APIContext, sha string) *Tree {
CopyPos := len(TreeURL) - 40 CopyPos := len(TreeURL) - 40
if len(Entries) > 1000 { if len(Entries) > 1000 {
tree.Entries = make([]TreeEntry, 1000) tree.Entries = make([]gitea.GitTreeEntry, 1000)
} else { } else {
tree.Entries = make([]TreeEntry, len(Entries)) tree.Entries = make([]gitea.GitTreeEntry, len(Entries))
} }
for e := range Entries { for e := range Entries {
if e > 1000 { if e > 1000 {