Browse Source

modes/org: code format for PR #4194

pull/3631/merge
Unknwon 8 years ago
parent
commit
e28bc7023f
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 2
      gogs.go
  2. 45
      models/org.go
  3. 2
      templates/.VERSION

2
gogs.go

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.9.169.0224 / 0.10 RC" const APP_VER = "0.9.170.0226 / 0.10 RC"
func init() { func init() {
setting.AppVer = APP_VER setting.AppVer = APP_VER

45
models/org.go

@ -10,7 +10,7 @@ import (
"os" "os"
"strings" "strings"
builder "github.com/go-xorm/builder" "github.com/go-xorm/builder"
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
) )
@ -487,8 +487,7 @@ func (org *User) GetUserTeams(userID int64) ([]*Team, error) {
return org.getUserTeams(x, userID) return org.getUserTeams(x, userID)
} }
// GetUserRepositories returns a range of repositories in organization // GetUserRepositories returns a range of repositories in organization which the user has access to,
// that the user with the given userID has access to,
// and total number of records based on given condition. // and total number of records based on given condition.
func (org *User) GetUserRepositories(userID int64, page, pageSize int) ([]*Repository, int64, error) { func (org *User) GetUserRepositories(userID int64, page, pageSize int) ([]*Repository, int64, error) {
teamIDs, err := org.GetUserTeamIDs(userID) teamIDs, err := org.GetUserTeamIDs(userID)
@ -501,29 +500,31 @@ func (org *User) GetUserRepositories(userID int64, page, pageSize int) ([]*Repos
} }
var teamRepoIDs []int64 var teamRepoIDs []int64
err = x.Table("team_repo").In("team_id", teamIDs).Distinct("repo_id").Find(&teamRepoIDs) if err = x.Table("team_repo").In("team_id", teamIDs).Distinct("repo_id").Find(&teamRepoIDs); err != nil {
if err != nil { return nil, 0, fmt.Errorf("get team repository IDs: %v", err)
return nil, 0, fmt.Errorf("get team repository ids: %v", err)
} }
if len(teamRepoIDs) == 0 { if len(teamRepoIDs) == 0 {
// team has no repo but "IN ()" is invalid SQL // team has no repo but "IN ()" is invalid SQL
teamRepoIDs = []int64{-1} // there is no repo with id=-1 teamRepoIDs = []int64{-1} // there is no repo with id=-1
} }
if page <= 0 { if page <= 0 {
page = 1 page = 1
} }
repos := make([]*Repository, 0, pageSize) repos := make([]*Repository, 0, pageSize)
err = x.Where("owner_id = ?", org.ID).And("is_private = ?", false). if err = x.Where("owner_id = ?", org.ID).
Or(builder.In("id", teamRepoIDs)).Desc("updated_unix"). And("is_private = ?", false).
Limit(pageSize, (page-1)*pageSize).Find(&repos) Or(builder.In("id", teamRepoIDs)).
if err != nil { Desc("updated_unix").
Limit(pageSize, (page-1)*pageSize).
Find(&repos); err != nil {
return nil, 0, fmt.Errorf("get user repositories: %v", err) return nil, 0, fmt.Errorf("get user repositories: %v", err)
} }
repo := new(Repository) repoCount, err := x.Where("owner_id = ?", org.ID).
repoCount, err := x.Where("owner_id = ?", org.ID).And("is_private = ?", false). And("is_private = ?", false).
Or(builder.In("id", teamRepoIDs)).Count(repo) Or(builder.In("id", teamRepoIDs)).
Count(new(Repository))
if err != nil { if err != nil {
return nil, 0, fmt.Errorf("count user repositories: %v", err) return nil, 0, fmt.Errorf("count user repositories: %v", err)
} }
@ -531,8 +532,7 @@ func (org *User) GetUserRepositories(userID int64, page, pageSize int) ([]*Repos
return repos, repoCount, nil return repos, repoCount, nil
} }
// GetUserMirrorRepositories returns mirror repositories of the organization // GetUserMirrorRepositories returns mirror repositories of the organization which the user has access to.
// that the user with the given userID has access to.
func (org *User) GetUserMirrorRepositories(userID int64) ([]*Repository, error) { func (org *User) GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
teamIDs, err := org.GetUserTeamIDs(userID) teamIDs, err := org.GetUserTeamIDs(userID)
if err != nil { if err != nil {
@ -541,21 +541,24 @@ func (org *User) GetUserMirrorRepositories(userID int64) ([]*Repository, error)
if len(teamIDs) == 0 { if len(teamIDs) == 0 {
teamIDs = []int64{-1} teamIDs = []int64{-1}
} }
var teamRepoIDs []int64 var teamRepoIDs []int64
err = x.Table("team_repo").In("team_id", teamIDs).Distinct("repo_id").Find(&teamRepoIDs) err = x.Table("team_repo").In("team_id", teamIDs).Distinct("repo_id").Find(&teamRepoIDs)
if err != nil { if err != nil {
return nil, fmt.Errorf("get team repository ids: %v", err) return nil, fmt.Errorf("get team repository ids: %v", err)
} }
if len(teamRepoIDs) == 0 { if len(teamRepoIDs) == 0 {
// team has no repo but "IN ()" is invalid SQL // team has no repo but "IN ()" is invalid SQL
teamRepoIDs = []int64{-1} // there is no repo with id=-1 teamRepoIDs = []int64{-1} // there is no repo with id=-1
} }
repos := make([]*Repository, 0, 10) repos := make([]*Repository, 0, 10)
err = x.Where("owner_id = ?", org.ID).And("is_private = ?", false). if err = x.Where("owner_id = ?", org.ID).
Or(builder.In("id", teamRepoIDs)).And("is_mirror = ?", true). And("is_private = ?", false).
Desc("updated_unix").Find(&repos) Or(builder.In("id", teamRepoIDs)).
if err != nil { And("is_mirror = ?", true). // Don't move up because it's an independent condition
Desc("updated_unix").
Find(&repos); err != nil {
return nil, fmt.Errorf("get user repositories: %v", err) return nil, fmt.Errorf("get user repositories: %v", err)
} }
return repos, nil return repos, nil

2
templates/.VERSION

@ -1 +1 @@
0.9.169.0224 / 0.10 RC 0.9.170.0226 / 0.10 RC
Loading…
Cancel
Save