Browse Source

api/repo: load attributes when listing user repositories (#4565)

pull/4584/head
Unknwon 7 years ago
parent
commit
11b1498a6e
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 2
      gogs.go
  2. 6
      models/access.go
  3. 2
      models/repo.go
  4. 6
      routes/api/v1/repo/repo.go
  5. 2
      templates/.VERSION

2
gogs.go

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/pkg/setting"
) )
const APP_VER = "0.11.21.0611" const APP_VER = "0.11.22.0621"
func init() { func init() {
setting.AppVer = APP_VER setting.AppVer = APP_VER

6
models/access.go

@ -112,14 +112,12 @@ func (u *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
repo, err := GetRepositoryByID(access.RepoID) repo, err := GetRepositoryByID(access.RepoID)
if err != nil { if err != nil {
if errors.IsRepoNotExist(err) { if errors.IsRepoNotExist(err) {
log.Error(4, "GetRepositoryByID: %v", err) log.Error(2, "GetRepositoryByID: %v", err)
continue continue
} }
return nil, err return nil, err
} }
if err = repo.GetOwner(); err != nil { if repo.OwnerID == u.ID {
return nil, err
} else if repo.OwnerID == u.ID {
continue continue
} }
repos[repo] = access.Mode repos[repo] = access.Mode

2
models/repo.go

@ -282,6 +282,8 @@ func (repo *Repository) HTMLURL() string {
return setting.AppURL + repo.FullName() return setting.AppURL + repo.FullName()
} }
// This method assumes following fields have been assigned with valid values:
// Required - BaseRepo (if fork)
// Arguments that are allowed to be nil: permission // Arguments that are allowed to be nil: permission
func (repo *Repository) APIFormat(permission *api.Permission) *api.Repository { func (repo *Repository) APIFormat(permission *api.Permission) *api.Repository {
cloneLink := repo.CloneLink() cloneLink := repo.CloneLink()

6
routes/api/v1/repo/repo.go

@ -101,6 +101,12 @@ func listUserRepositories(c *context.APIContext, username string) {
return return
} }
if err = models.RepositoryList(ownRepos).LoadAttributes(); err != nil {
c.Error(500, "LoadAttributes(ownRepos)", err)
return
}
// Early return for querying other user's repositories
if c.User.ID != user.ID { if c.User.ID != user.ID {
repos := make([]*api.Repository, len(ownRepos)) repos := make([]*api.Repository, len(ownRepos))
for i := range ownRepos { for i := range ownRepos {

2
templates/.VERSION

@ -1 +1 @@
0.11.21.0611 0.11.22.0621
Loading…
Cancel
Save