@@ -27,8 +27,8 @@ type IssuesOptions struct { //nolint
2727 RepoIDs []int64 // overwrites RepoCond if the length is not 0
2828 AllPublic bool // include also all public repositories
2929 RepoCond builder.Cond
30- AssigneeID int64
31- PosterID int64
30+ AssigneeID optional. Option [ int64 ]
31+ PosterID optional. Option [ int64 ]
3232 MentionedID int64
3333 ReviewRequestedID int64
3434 ReviewedID int64
@@ -231,15 +231,8 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) {
231231 sess .And ("issue.is_closed=?" , opts .IsClosed .Value ())
232232 }
233233
234- if opts .AssigneeID > 0 {
235- applyAssigneeCondition (sess , opts .AssigneeID )
236- } else if opts .AssigneeID == db .NoConditionID {
237- sess .Where ("issue.id NOT IN (SELECT issue_id FROM issue_assignees)" )
238- }
239-
240- if opts .PosterID > 0 {
241- applyPosterCondition (sess , opts .PosterID )
242- }
234+ applyAssigneeCondition (sess , opts .AssigneeID )
235+ applyPosterCondition (sess , opts .PosterID )
243236
244237 if opts .MentionedID > 0 {
245238 applyMentionedCondition (sess , opts .MentionedID )
@@ -359,13 +352,26 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati
359352 return cond
360353}
361354
362- func applyAssigneeCondition (sess * xorm.Session , assigneeID int64 ) {
363- sess .Join ("INNER" , "issue_assignees" , "issue.id = issue_assignees.issue_id" ).
364- And ("issue_assignees.assignee_id = ?" , assigneeID )
355+ func applyAssigneeCondition (sess * xorm.Session , assigneeID optional.Option [int64 ]) {
356+ if assigneeID == nil || assigneeID .Value () == 0 {
357+ return
358+ }
359+ if assigneeID .Value () == db .NoConditionID {
360+ sess .Where ("issue.id NOT IN (SELECT issue_id FROM issue_assignees)" )
361+ } else {
362+ sess .Join ("INNER" , "issue_assignees" , "issue.id = issue_assignees.issue_id" ).
363+ And ("issue_assignees.assignee_id = ?" , assigneeID .Value ())
364+ }
365365}
366366
367- func applyPosterCondition (sess * xorm.Session , posterID int64 ) {
368- sess .And ("issue.poster_id=?" , posterID )
367+ func applyPosterCondition (sess * xorm.Session , posterID optional.Option [int64 ]) {
368+ if posterID == nil {
369+ return
370+ }
371+ // poster doesn't need to support db.NoConditionID(-1), so just use the value as-is
372+ if posterID .Has () {
373+ sess .And ("issue.poster_id=?" , posterID .Value ())
374+ }
369375}
370376
371377func applyMentionedCondition (sess * xorm.Session , mentionedID int64 ) {
0 commit comments