@@ -47,10 +47,10 @@ func GetTeamRepositories(ctx context.Context, opts *SearchTeamRepoOptions) (Repo
47
47
// AccessibleReposEnvironment operations involving the repositories that are
48
48
// accessible to a particular user
49
49
type AccessibleReposEnvironment interface {
50
- CountRepos () (int64 , error )
51
- RepoIDs (page , pageSize int ) ([]int64 , error )
52
- Repos (page , pageSize int ) (RepositoryList , error )
53
- MirrorRepos () (RepositoryList , error )
50
+ CountRepos (ctx context. Context ) (int64 , error )
51
+ RepoIDs (ctx context. Context , page , pageSize int ) ([]int64 , error )
52
+ Repos (ctx context. Context , page , pageSize int ) (RepositoryList , error )
53
+ MirrorRepos (ctx context. Context ) (RepositoryList , error )
54
54
AddKeyword (keyword string )
55
55
SetSort (db.SearchOrderBy )
56
56
}
@@ -60,7 +60,6 @@ type accessibleReposEnv struct {
60
60
user * user_model.User
61
61
team * org_model.Team
62
62
teamIDs []int64
63
- ctx context.Context
64
63
keyword string
65
64
orderBy db.SearchOrderBy
66
65
}
@@ -86,18 +85,16 @@ func AccessibleReposEnv(ctx context.Context, org *org_model.Organization, userID
86
85
org : org ,
87
86
user : user ,
88
87
teamIDs : teamIDs ,
89
- ctx : ctx ,
90
88
orderBy : db .SearchOrderByRecentUpdated ,
91
89
}, nil
92
90
}
93
91
94
92
// AccessibleTeamReposEnv an AccessibleReposEnvironment for the repositories in `org`
95
93
// that are accessible to the specified team.
96
- func AccessibleTeamReposEnv (ctx context. Context , org * org_model.Organization , team * org_model.Team ) AccessibleReposEnvironment {
94
+ func AccessibleTeamReposEnv (org * org_model.Organization , team * org_model.Team ) AccessibleReposEnvironment {
97
95
return & accessibleReposEnv {
98
96
org : org ,
99
97
team : team ,
100
- ctx : ctx ,
101
98
orderBy : db .SearchOrderByRecentUpdated ,
102
99
}
103
100
}
@@ -123,8 +120,8 @@ func (env *accessibleReposEnv) cond() builder.Cond {
123
120
return cond
124
121
}
125
122
126
- func (env * accessibleReposEnv ) CountRepos () (int64 , error ) {
127
- repoCount , err := db .GetEngine (env . ctx ).
123
+ func (env * accessibleReposEnv ) CountRepos (ctx context. Context ) (int64 , error ) {
124
+ repoCount , err := db .GetEngine (ctx ).
128
125
Join ("INNER" , "team_repo" , "`team_repo`.repo_id=`repository`.id" ).
129
126
Where (env .cond ()).
130
127
Distinct ("`repository`.id" ).
@@ -135,13 +132,13 @@ func (env *accessibleReposEnv) CountRepos() (int64, error) {
135
132
return repoCount , nil
136
133
}
137
134
138
- func (env * accessibleReposEnv ) RepoIDs (page , pageSize int ) ([]int64 , error ) {
135
+ func (env * accessibleReposEnv ) RepoIDs (ctx context. Context , page , pageSize int ) ([]int64 , error ) {
139
136
if page <= 0 {
140
137
page = 1
141
138
}
142
139
143
140
repoIDs := make ([]int64 , 0 , pageSize )
144
- return repoIDs , db .GetEngine (env . ctx ).
141
+ return repoIDs , db .GetEngine (ctx ).
145
142
Table ("repository" ).
146
143
Join ("INNER" , "team_repo" , "`team_repo`.repo_id=`repository`.id" ).
147
144
Where (env .cond ()).
@@ -152,8 +149,8 @@ func (env *accessibleReposEnv) RepoIDs(page, pageSize int) ([]int64, error) {
152
149
Find (& repoIDs )
153
150
}
154
151
155
- func (env * accessibleReposEnv ) Repos (page , pageSize int ) (RepositoryList , error ) {
156
- repoIDs , err := env .RepoIDs (page , pageSize )
152
+ func (env * accessibleReposEnv ) Repos (ctx context. Context , page , pageSize int ) (RepositoryList , error ) {
153
+ repoIDs , err := env .RepoIDs (ctx , page , pageSize )
157
154
if err != nil {
158
155
return nil , fmt .Errorf ("GetUserRepositoryIDs: %w" , err )
159
156
}
@@ -163,15 +160,15 @@ func (env *accessibleReposEnv) Repos(page, pageSize int) (RepositoryList, error)
163
160
return repos , nil
164
161
}
165
162
166
- return repos , db .GetEngine (env . ctx ).
163
+ return repos , db .GetEngine (ctx ).
167
164
In ("`repository`.id" , repoIDs ).
168
165
OrderBy (string (env .orderBy )).
169
166
Find (& repos )
170
167
}
171
168
172
- func (env * accessibleReposEnv ) MirrorRepoIDs () ([]int64 , error ) {
169
+ func (env * accessibleReposEnv ) MirrorRepoIDs (ctx context. Context ) ([]int64 , error ) {
173
170
repoIDs := make ([]int64 , 0 , 10 )
174
- return repoIDs , db .GetEngine (env . ctx ).
171
+ return repoIDs , db .GetEngine (ctx ).
175
172
Table ("repository" ).
176
173
Join ("INNER" , "team_repo" , "`team_repo`.repo_id=`repository`.id AND `repository`.is_mirror=?" , true ).
177
174
Where (env .cond ()).
@@ -181,8 +178,8 @@ func (env *accessibleReposEnv) MirrorRepoIDs() ([]int64, error) {
181
178
Find (& repoIDs )
182
179
}
183
180
184
- func (env * accessibleReposEnv ) MirrorRepos () (RepositoryList , error ) {
185
- repoIDs , err := env .MirrorRepoIDs ()
181
+ func (env * accessibleReposEnv ) MirrorRepos (ctx context. Context ) (RepositoryList , error ) {
182
+ repoIDs , err := env .MirrorRepoIDs (ctx )
186
183
if err != nil {
187
184
return nil , fmt .Errorf ("MirrorRepoIDs: %w" , err )
188
185
}
@@ -192,7 +189,7 @@ func (env *accessibleReposEnv) MirrorRepos() (RepositoryList, error) {
192
189
return repos , nil
193
190
}
194
191
195
- return repos , db .GetEngine (env . ctx ).
192
+ return repos , db .GetEngine (ctx ).
196
193
In ("`repository`.id" , repoIDs ).
197
194
Find (& repos )
198
195
}
0 commit comments