Skip to content

Commit a0a9de8

Browse files
committed
extend models.IssuesOptions to have more specific repo filter options
1 parent 0abd8b0 commit a0a9de8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

models/issue.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,9 @@ func GetIssuesByIDs(issueIDs []int64) ([]*Issue, error) {
11941194
// IssuesOptions represents options of an issue.
11951195
type IssuesOptions struct {
11961196
db.ListOptions
1197-
RepoIDs []int64 // include all repos if empty
1197+
RepoIDs []int64 // include all repos if empty // TODO: migrate to RepoCond
1198+
RepoID int64 // overwrites RepoCond if not 0
1199+
RepoCond builder.Cond
11981200
AssigneeID int64
11991201
PosterID int64
12001202
MentionedID int64
@@ -1285,8 +1287,14 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
12851287
sess.In("issue.id", opts.IssueIDs)
12861288
}
12871289

1288-
if len(opts.RepoIDs) > 0 {
1289-
applyReposCondition(sess, opts.RepoIDs)
1290+
if opts.RepoCond == nil && len(opts.RepoIDs) != 0 {
1291+
opts.RepoCond = builder.In("issue.repo_id", opts.RepoIDs)
1292+
}
1293+
if opts.RepoID != 0 {
1294+
opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoID}
1295+
}
1296+
if opts.RepoCond != nil {
1297+
sess.And(opts.RepoCond)
12901298
}
12911299

12921300
switch opts.IsClosed {
@@ -1412,10 +1420,6 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati
14121420
return cond
14131421
}
14141422

1415-
func applyReposCondition(sess *xorm.Session, repoIDs []int64) *xorm.Session {
1416-
return sess.In("issue.repo_id", repoIDs)
1417-
}
1418-
14191423
func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) *xorm.Session {
14201424
return sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
14211425
And("issue_assignees.assignee_id = ?", assigneeID)

0 commit comments

Comments
 (0)