Skip to content

Commit 3b92f9b

Browse files
committed
Fix conflicts
1 parent cb340f4 commit 3b92f9b

File tree

5 files changed

+48
-60
lines changed

5 files changed

+48
-60
lines changed

models/repo/repo.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -731,15 +731,6 @@ func CountUserRepositories(userID int64, private bool) int64 {
731731
return countRepositories(userID, private)
732732
}
733733

734-
// GetUserMirrorRepositories returns a list of mirror repositories of given user.
735-
func GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
736-
repos := make([]*Repository, 0, 10)
737-
return repos, db.GetEngine(db.DefaultContext).
738-
Where("owner_id = ?", userID).
739-
And("is_mirror = ?", true).
740-
Find(&repos)
741-
}
742-
743734
func getRepositoryCount(e db.Engine, ownerID int64) (int64, error) {
744735
return e.Count(&Repository{OwnerID: ownerID})
745736
}
@@ -766,25 +757,3 @@ func GetPublicRepositoryCount(u *user_model.User) (int64, error) {
766757
func GetPrivateRepositoryCount(u *user_model.User) (int64, error) {
767758
return getPrivateRepositoryCount(db.GetEngine(db.DefaultContext), u)
768759
}
769-
770-
// IterateRepository iterate repositories
771-
func IterateRepository(f func(repo *Repository) error) error {
772-
var start int
773-
batchSize := setting.Database.IterateBufferSize
774-
for {
775-
repos := make([]*Repository, 0, batchSize)
776-
if err := db.GetEngine(db.DefaultContext).Limit(batchSize, start).Find(&repos); err != nil {
777-
return err
778-
}
779-
if len(repos) == 0 {
780-
return nil
781-
}
782-
start += len(repos)
783-
784-
for _, repo := range repos {
785-
if err := f(repo); err != nil {
786-
return err
787-
}
788-
}
789-
}
790-
}

models/repo/repo_list.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package repo
6+
7+
import (
8+
"code.gitea.io/gitea/models/db"
9+
"code.gitea.io/gitea/modules/setting"
10+
)
11+
12+
// GetUserMirrorRepositories returns a list of mirror repositories of given user.
13+
func GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
14+
repos := make([]*Repository, 0, 10)
15+
return repos, db.GetEngine(db.DefaultContext).
16+
Where("owner_id = ?", userID).
17+
And("is_mirror = ?", true).
18+
Find(&repos)
19+
}
20+
21+
// IterateRepository iterate repositories
22+
func IterateRepository(f func(repo *Repository) error) error {
23+
var start int
24+
batchSize := setting.Database.IterateBufferSize
25+
for {
26+
repos := make([]*Repository, 0, batchSize)
27+
if err := db.GetEngine(db.DefaultContext).Limit(batchSize, start).Find(&repos); err != nil {
28+
return err
29+
}
30+
if len(repos) == 0 {
31+
return nil
32+
}
33+
start += len(repos)
34+
35+
for _, repo := range repos {
36+
if err := f(repo); err != nil {
37+
return err
38+
}
39+
}
40+
}
41+
}
42+
43+
// FindReposMapByIDs find repos as map
44+
func FindReposMapByIDs(repoIDs []int64, res map[int64]*Repository) error {
45+
return db.GetEngine(db.DefaultContext).In("id", repoIDs).Find(&res)
46+
}

models/repo_list.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,3 @@ func GetUserRepositories(opts *SearchRepoOptions) ([]*repo_model.Repository, int
641641
repos := make([]*repo_model.Repository, 0, opts.PageSize)
642642
return repos, count, db.SetSessionPagination(sess, opts).Find(&repos)
643643
}
644-
645-
// FindReposMapByIDs find repos as map
646-
func FindReposMapByIDs(repoIDs []int64, res map[int64]*Repository) error {
647-
return db.GetEngine(db.DefaultContext).In("id", repoIDs).Find(&res)
648-
}

models/user_test.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,3 @@ func testIsUserOrgOwner(t *testing.T, uid, orgID int64, expected bool) {
9898
assert.NoError(t, err)
9999
assert.Equal(t, expected, is)
100100
}
101-
102-
func TestGetOrgRepositoryIDs(t *testing.T) {
103-
assert.NoError(t, unittest.PrepareTestDatabase())
104-
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
105-
user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}).(*user_model.User)
106-
user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
107-
108-
accessibleRepos, err := GetOrgRepositoryIDs(user2)
109-
assert.NoError(t, err)
110-
// User 2's team has access to private repos 3, 5, repo 32 is a public repo of the organization
111-
assert.Equal(t, []int64{3, 5, 23, 24, 32}, accessibleRepos)
112-
113-
accessibleRepos, err = GetOrgRepositoryIDs(user4)
114-
assert.NoError(t, err)
115-
// User 4's team has access to private repo 3, repo 32 is a public repo of the organization
116-
assert.Equal(t, []int64{3, 32}, accessibleRepos)
117-
118-
accessibleRepos, err = GetOrgRepositoryIDs(user5)
119-
assert.NoError(t, err)
120-
// User 5's team has no access to any repo
121-
assert.Len(t, accessibleRepos, 0)
122-
}

routers/web/user/home.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,14 +701,14 @@ func loadRepoByIDs(ctxUser *user_model.User, issueCountByRepo map[int64]int64, u
701701
}
702702
repoIDs = append(repoIDs, id)
703703
if len(repoIDs) == 500 {
704-
if err := models.FindReposMapByIDs(repoIDs, totalRes); err != nil {
704+
if err := repo_model.FindReposMapByIDs(repoIDs, totalRes); err != nil {
705705
return nil, err
706706
}
707707
repoIDs = make([]int64, 0, 500)
708708
}
709709
}
710710
if len(repoIDs) > 0 {
711-
if err := models.FindReposMapByIDs(repoIDs, totalRes); err != nil {
711+
if err := repo_model.FindReposMapByIDs(repoIDs, totalRes); err != nil {
712712
return nil, err
713713
}
714714
}

0 commit comments

Comments
 (0)