diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-21 01:09:22 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-21 01:09:22 -0400 |
commit | 369ddf76a8ae6916ab72f1fa26c81b44c456c6ea (patch) | |
tree | 3e26392ef3ff4569cc077432e507e848f907df8a /models/repo.go | |
parent | 53a17bbd240e0dd3755b7a666792d69e358f3e00 (diff) | |
download | gitea-369ddf76a8ae6916ab72f1fa26c81b44c456c6ea.tar.gz gitea-369ddf76a8ae6916ab72f1fa26c81b44c456c6ea.zip |
Batch fix
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/models/repo.go b/models/repo.go index f5ceaf7631..93f68ceddf 100644 --- a/models/repo.go +++ b/models/repo.go @@ -323,11 +323,33 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep return nil } +// UserRepo reporesents a repository with user name. +type UserRepo struct { + *Repository + UserName string +} + // GetRepos returns given number of repository objects with offset. -func GetRepos(num, offset int) ([]Repository, error) { +func GetRepos(num, offset int) ([]UserRepo, error) { repos := make([]Repository, 0, num) - err := orm.Limit(num, offset).Asc("id").Find(&repos) - return repos, err + if err := orm.Limit(num, offset).Asc("id").Find(&repos); err != nil { + return nil, err + } + + urepos := make([]UserRepo, len(repos)) + for i := range repos { + urepos[i].Repository = &repos[i] + u := new(User) + has, err := orm.Id(urepos[i].Repository.OwnerId).Get(u) + if err != nil { + return nil, err + } else if !has { + return nil, ErrUserNotExist + } + urepos[i].UserName = u.Name + } + + return urepos, nil } func RepoPath(userName, repoName string) string { |