@@ -155,6 +155,18 @@ func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sess
155155 return sess
156156}
157157
158+ func applyProjectCondition (sess * xorm.Session , opts * IssuesOptions ) * xorm.Session {
159+ if opts .ProjectID > 0 { // specific project
160+ sess .Join ("INNER" , "project_issue" , "issue.id = project_issue.issue_id" ).
161+ And ("project_issue.project_id=?" , opts .ProjectID )
162+ } else if opts .ProjectID == db .NoConditionID { // show those that are in no project
163+ sess .And (builder .NotIn ("issue.id" , builder .Select ("issue_id" ).From ("project_issue" ).And (builder.Neq {"project_id" : 0 })))
164+ }
165+ // opts.ProjectID == 0 means all projects,
166+ // do not need to apply any condition
167+ return sess
168+ }
169+
158170func applyRepoConditions (sess * xorm.Session , opts * IssuesOptions ) * xorm.Session {
159171 if len (opts .RepoIDs ) == 1 {
160172 opts .RepoCond = builder.Eq {"issue.repo_id" : opts .RepoIDs [0 ]}
@@ -213,12 +225,7 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
213225 sess .And (builder.Lte {"issue.updated_unix" : opts .UpdatedBeforeUnix })
214226 }
215227
216- if opts .ProjectID > 0 {
217- sess .Join ("INNER" , "project_issue" , "issue.id = project_issue.issue_id" ).
218- And ("project_issue.project_id=?" , opts .ProjectID )
219- } else if opts .ProjectID == db .NoConditionID { // show those that are in no project
220- sess .And (builder .NotIn ("issue.id" , builder .Select ("issue_id" ).From ("project_issue" )))
221- }
228+ applyProjectCondition (sess , opts )
222229
223230 if opts .ProjectBoardID != 0 {
224231 if opts .ProjectBoardID > 0 {
0 commit comments