File tree 3 files changed +34
-24
lines changed 3 files changed +34
-24
lines changed Original file line number Diff line number Diff line change @@ -1306,18 +1306,19 @@ func GetIssuesByIDs(issueIDs []int64) ([]*Issue, error) {
1306
1306
1307
1307
// IssuesOptions represents options of an issue.
1308
1308
type IssuesOptions struct {
1309
- RepoIDs []int64 // include all repos if empty
1310
- AssigneeID int64
1311
- PosterID int64
1312
- MentionedID int64
1313
- MilestoneID int64
1314
- Page int
1315
- PageSize int
1316
- IsClosed util.OptionalBool
1317
- IsPull util.OptionalBool
1318
- LabelIDs []int64
1319
- SortType string
1320
- IssueIDs []int64
1309
+ RepoIDs []int64 // include all repos if empty
1310
+ RepoSubQuery * builder.Builder
1311
+ AssigneeID int64
1312
+ PosterID int64
1313
+ MentionedID int64
1314
+ MilestoneID int64
1315
+ Page int
1316
+ PageSize int
1317
+ IsClosed util.OptionalBool
1318
+ IsPull util.OptionalBool
1319
+ LabelIDs []int64
1320
+ SortType string
1321
+ IssueIDs []int64
1321
1322
}
1322
1323
1323
1324
// sortIssuesSession sort an issues-related session based on the provided
@@ -1360,7 +1361,9 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
1360
1361
sess .In ("issue.id" , opts .IssueIDs )
1361
1362
}
1362
1363
1363
- if len (opts .RepoIDs ) > 0 {
1364
+ if opts .RepoSubQuery != nil {
1365
+ sess .In ("issue.repo_id" , opts .RepoSubQuery )
1366
+ } else if len (opts .RepoIDs ) > 0 {
1364
1367
// In case repository IDs are provided but actually no repository has issue.
1365
1368
sess .In ("issue.repo_id" , opts .RepoIDs )
1366
1369
}
Original file line number Diff line number Diff line change @@ -629,6 +629,17 @@ func (u *User) GetRepositoryIDs(units ...UnitType) ([]int64, error) {
629
629
return ids , sess .Where ("owner_id = ?" , u .ID ).Find (& ids )
630
630
}
631
631
632
+ // UnitRepositoriesSubQuery returns repositories query builder according units
633
+ func (u * User ) UnitRepositoriesSubQuery (units ... UnitType ) * builder.Builder {
634
+ b := builder .Select ("repository.id" ).From ("repository" )
635
+
636
+ if len (units ) > 0 {
637
+ b = b .Join ("INNER" , "repo_unit" , "repository.id = repo_unit.repo_id" )
638
+ b = b .Where (builder .In ("repo_unit.type" , units ))
639
+ }
640
+ return b .Where (builder.Eq {"owner_id" : u .ID })
641
+ }
642
+
632
643
// GetOrgRepositoryIDs returns repositories IDs where user's team owned and has unittypes
633
644
func (u * User ) GetOrgRepositoryIDs (units ... UnitType ) ([]int64 , error ) {
634
645
var ids []int64
Original file line number Diff line number Diff line change @@ -200,6 +200,12 @@ func Issues(ctx *context.Context) {
200
200
// Get repositories.
201
201
var err error
202
202
var userRepoIDs []int64
203
+ opts := & models.IssuesOptions {
204
+ IsClosed : util .OptionalBoolOf (isShowClosed ),
205
+ IsPull : util .OptionalBoolOf (isPullList ),
206
+ SortType : sortType ,
207
+ }
208
+
203
209
if ctxUser .IsOrganization () {
204
210
env , err := ctxUser .AccessibleReposEnv (ctx .User .ID )
205
211
if err != nil {
@@ -216,22 +222,12 @@ func Issues(ctx *context.Context) {
216
222
if isPullList {
217
223
unitType = models .UnitTypePullRequests
218
224
}
219
- userRepoIDs , err = ctxUser .GetAccessRepoIDs (unitType )
220
- if err != nil {
221
- ctx .ServerError ("ctxUser.GetAccessRepoIDs" , err )
222
- return
223
- }
225
+ opts .RepoSubQuery = ctxUser .UnitRepositoriesSubQuery (unitType )
224
226
}
225
227
if len (userRepoIDs ) == 0 {
226
228
userRepoIDs = []int64 {- 1 }
227
229
}
228
230
229
- opts := & models.IssuesOptions {
230
- IsClosed : util .OptionalBoolOf (isShowClosed ),
231
- IsPull : util .OptionalBoolOf (isPullList ),
232
- SortType : sortType ,
233
- }
234
-
235
231
if repoID > 0 {
236
232
opts .RepoIDs = []int64 {repoID }
237
233
}
You can’t perform that action at this time.
0 commit comments