@@ -5,7 +5,6 @@ package issues
55
66import (
77 "context"
8- "errors"
98 "fmt"
109
1110 "code.gitea.io/gitea/models/db"
@@ -181,195 +180,6 @@ func applyIssuesOptions(sess *xorm.Session, opts *IssuesOptions, issueIDs []int6
181180 return sess
182181}
183182
184- // GetUserIssueStats returns issue statistic information for dashboard by given conditions.
185- func GetUserIssueStats (filterMode int , opts IssuesOptions ) (* IssueStats , error ) {
186- if opts .User == nil {
187- return nil , errors .New ("issue stats without user" )
188- }
189- if opts .IsPull .IsNone () {
190- return nil , errors .New ("unaccepted ispull option" )
191- }
192-
193- var err error
194- stats := & IssueStats {}
195-
196- cond := builder .NewCond ()
197-
198- cond = cond .And (builder.Eq {"issue.is_pull" : opts .IsPull .IsTrue ()})
199-
200- if len (opts .RepoIDs ) > 0 {
201- cond = cond .And (builder .In ("issue.repo_id" , opts .RepoIDs ))
202- }
203- if len (opts .IssueIDs ) > 0 {
204- cond = cond .And (builder .In ("issue.id" , opts .IssueIDs ))
205- }
206- if opts .RepoCond != nil {
207- cond = cond .And (opts .RepoCond )
208- }
209-
210- if opts .User != nil {
211- cond = cond .And (issuePullAccessibleRepoCond ("issue.repo_id" , opts .User .ID , opts .Org , opts .Team , opts .IsPull .IsTrue ()))
212- }
213-
214- sess := func (cond builder.Cond ) * xorm.Session {
215- s := db .GetEngine (db .DefaultContext ).
216- Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" ).
217- Where (cond )
218- if len (opts .LabelIDs ) > 0 {
219- s .Join ("INNER" , "issue_label" , "issue_label.issue_id = issue.id" ).
220- In ("issue_label.label_id" , opts .LabelIDs )
221- }
222-
223- if opts .IsArchived != util .OptionalBoolNone {
224- s .And (builder.Eq {"repository.is_archived" : opts .IsArchived .IsTrue ()})
225- }
226- return s
227- }
228-
229- switch filterMode {
230- case FilterModeAll , FilterModeYourRepositories :
231- stats .OpenCount , err = sess (cond ).
232- And ("issue.is_closed = ?" , false ).
233- Count (new (Issue ))
234- if err != nil {
235- return nil , err
236- }
237- stats .ClosedCount , err = sess (cond ).
238- And ("issue.is_closed = ?" , true ).
239- Count (new (Issue ))
240- if err != nil {
241- return nil , err
242- }
243- case FilterModeAssign :
244- stats .OpenCount , err = applyAssigneeCondition (sess (cond ), opts .User .ID ).
245- And ("issue.is_closed = ?" , false ).
246- Count (new (Issue ))
247- if err != nil {
248- return nil , err
249- }
250- stats .ClosedCount , err = applyAssigneeCondition (sess (cond ), opts .User .ID ).
251- And ("issue.is_closed = ?" , true ).
252- Count (new (Issue ))
253- if err != nil {
254- return nil , err
255- }
256- case FilterModeCreate :
257- stats .OpenCount , err = applyPosterCondition (sess (cond ), opts .User .ID ).
258- And ("issue.is_closed = ?" , false ).
259- Count (new (Issue ))
260- if err != nil {
261- return nil , err
262- }
263- stats .ClosedCount , err = applyPosterCondition (sess (cond ), opts .User .ID ).
264- And ("issue.is_closed = ?" , true ).
265- Count (new (Issue ))
266- if err != nil {
267- return nil , err
268- }
269- case FilterModeMention :
270- stats .OpenCount , err = applyMentionedCondition (sess (cond ), opts .User .ID ).
271- And ("issue.is_closed = ?" , false ).
272- Count (new (Issue ))
273- if err != nil {
274- return nil , err
275- }
276- stats .ClosedCount , err = applyMentionedCondition (sess (cond ), opts .User .ID ).
277- And ("issue.is_closed = ?" , true ).
278- Count (new (Issue ))
279- if err != nil {
280- return nil , err
281- }
282- case FilterModeReviewRequested :
283- stats .OpenCount , err = applyReviewRequestedCondition (sess (cond ), opts .User .ID ).
284- And ("issue.is_closed = ?" , false ).
285- Count (new (Issue ))
286- if err != nil {
287- return nil , err
288- }
289- stats .ClosedCount , err = applyReviewRequestedCondition (sess (cond ), opts .User .ID ).
290- And ("issue.is_closed = ?" , true ).
291- Count (new (Issue ))
292- if err != nil {
293- return nil , err
294- }
295- case FilterModeReviewed :
296- stats .OpenCount , err = applyReviewedCondition (sess (cond ), opts .User .ID ).
297- And ("issue.is_closed = ?" , false ).
298- Count (new (Issue ))
299- if err != nil {
300- return nil , err
301- }
302- stats .ClosedCount , err = applyReviewedCondition (sess (cond ), opts .User .ID ).
303- And ("issue.is_closed = ?" , true ).
304- Count (new (Issue ))
305- if err != nil {
306- return nil , err
307- }
308- }
309-
310- cond = cond .And (builder.Eq {"issue.is_closed" : opts .IsClosed .IsTrue ()})
311- stats .AssignCount , err = applyAssigneeCondition (sess (cond ), opts .User .ID ).Count (new (Issue ))
312- if err != nil {
313- return nil , err
314- }
315-
316- stats .CreateCount , err = applyPosterCondition (sess (cond ), opts .User .ID ).Count (new (Issue ))
317- if err != nil {
318- return nil , err
319- }
320-
321- stats .MentionCount , err = applyMentionedCondition (sess (cond ), opts .User .ID ).Count (new (Issue ))
322- if err != nil {
323- return nil , err
324- }
325-
326- stats .YourRepositoriesCount , err = sess (cond ).Count (new (Issue ))
327- if err != nil {
328- return nil , err
329- }
330-
331- stats .ReviewRequestedCount , err = applyReviewRequestedCondition (sess (cond ), opts .User .ID ).Count (new (Issue ))
332- if err != nil {
333- return nil , err
334- }
335-
336- stats .ReviewedCount , err = applyReviewedCondition (sess (cond ), opts .User .ID ).Count (new (Issue ))
337- if err != nil {
338- return nil , err
339- }
340-
341- return stats , nil
342- }
343-
344- // GetRepoIssueStats returns number of open and closed repository issues by given filter mode.
345- func GetRepoIssueStats (repoID , uid int64 , filterMode int , isPull bool ) (numOpen , numClosed int64 ) {
346- countSession := func (isClosed , isPull bool , repoID int64 ) * xorm.Session {
347- sess := db .GetEngine (db .DefaultContext ).
348- Where ("is_closed = ?" , isClosed ).
349- And ("is_pull = ?" , isPull ).
350- And ("repo_id = ?" , repoID )
351-
352- return sess
353- }
354-
355- openCountSession := countSession (false , isPull , repoID )
356- closedCountSession := countSession (true , isPull , repoID )
357-
358- switch filterMode {
359- case FilterModeAssign :
360- applyAssigneeCondition (openCountSession , uid )
361- applyAssigneeCondition (closedCountSession , uid )
362- case FilterModeCreate :
363- applyPosterCondition (openCountSession , uid )
364- applyPosterCondition (closedCountSession , uid )
365- }
366-
367- openResult , _ := openCountSession .Count (new (Issue ))
368- closedResult , _ := closedCountSession .Count (new (Issue ))
369-
370- return openResult , closedResult
371- }
372-
373183// CountOrphanedIssues count issues without a repo
374184func CountOrphanedIssues (ctx context.Context ) (int64 , error ) {
375185 return db .GetEngine (ctx ).
0 commit comments