0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-22 15:01:11 +01:00

clean up code

This commit is contained in:
Unknwon 2015-11-16 23:33:40 -05:00
parent 114e6790f8
commit ab9411be2a
3 changed files with 23 additions and 42 deletions

View file

@ -1865,9 +1865,6 @@ func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Reposit
} }
func (repo *Repository) GetForks() ([]*Repository, error) { func (repo *Repository) GetForks() ([]*Repository, error) {
forks := make([]*Repository, 0, 10) forks := make([]*Repository, 0, repo.NumForks)
return forks, x.Find(&forks, &Repository{ForkID: repo.ID})
err := x.Find(&forks, &Repository{ForkID: repo.ID})
return forks, err
} }

View file

@ -1,37 +0,0 @@
// Copyright 2014 The Gogs 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 (
"fmt"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware"
)
const (
FORKS base.TplName = "repo/forks"
)
func Forks(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repos.forks")
forks, err := ctx.Repo.Repository.GetForks()
if err != nil {
ctx.Handle(500, "GetForks", err)
return
}
for _, fork := range forks {
if err = fork.GetOwner(); err != nil {
ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", fork.ID, err))
return
}
}
ctx.Data["Forks"] = forks
ctx.HTML(200, FORKS)
}

View file

@ -24,6 +24,7 @@ import (
const ( const (
HOME base.TplName = "repo/home" HOME base.TplName = "repo/home"
WATCHERS base.TplName = "repo/watchers" WATCHERS base.TplName = "repo/watchers"
FORKS base.TplName = "repo/forks"
) )
func Home(ctx *middleware.Context) { func Home(ctx *middleware.Context) {
@ -278,3 +279,23 @@ func Stars(ctx *middleware.Context) {
ctx.Data["PageIsStargazers"] = true ctx.Data["PageIsStargazers"] = true
renderItems(ctx, ctx.Repo.Repository.NumStars, ctx.Repo.Repository.GetStargazers) renderItems(ctx, ctx.Repo.Repository.NumStars, ctx.Repo.Repository.GetStargazers)
} }
func Forks(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("repos.forks")
forks, err := ctx.Repo.Repository.GetForks()
if err != nil {
ctx.Handle(500, "GetForks", err)
return
}
for _, fork := range forks {
if err = fork.GetOwner(); err != nil {
ctx.Handle(500, "GetOwner", err)
return
}
}
ctx.Data["Forks"] = forks
ctx.HTML(200, FORKS)
}