@@ -168,6 +168,18 @@ func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sess
168168 return sess
169169}
170170
171+ func applyProjectCondition (sess * xorm.Session , opts * IssuesOptions ) * xorm.Session {
172+ if opts .ProjectID > 0 { // specific project
173+ sess .Join ("INNER" , "project_issue" , "issue.id = project_issue.issue_id" ).
174+ And ("project_issue.project_id=?" , opts .ProjectID )
175+ } else if opts .ProjectID == db .NoConditionID { // show those that are in no project
176+ sess .And (builder .NotIn ("issue.id" , builder .Select ("issue_id" ).From ("project_issue" ).And (builder.Neq {"project_id" : 0 })))
177+ }
178+ // opts.ProjectID == 0 means all projects,
179+ // do not need to apply any condition
180+ return sess
181+ }
182+
171183func applyRepoConditions (sess * xorm.Session , opts * IssuesOptions ) * xorm.Session {
172184 if len (opts .RepoIDs ) == 1 {
173185 opts .RepoCond = builder.Eq {"issue.repo_id" : opts .RepoIDs [0 ]}
@@ -226,12 +238,7 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
226238 sess .And (builder.Lte {"issue.updated_unix" : opts .UpdatedBeforeUnix })
227239 }
228240
229- if opts .ProjectID > 0 {
230- sess .Join ("INNER" , "project_issue" , "issue.id = project_issue.issue_id" ).
231- And ("project_issue.project_id=?" , opts .ProjectID )
232- } else if opts .ProjectID == db .NoConditionID { // show those that are in no project
233- sess .And (builder .NotIn ("issue.id" , builder .Select ("issue_id" ).From ("project_issue" )))
234- }
241+ applyProjectCondition (sess , opts )
235242
236243 if opts .ProjectBoardID != 0 {
237244 if opts .ProjectBoardID > 0 {
0 commit comments