From 987152ba408b03fe0b15dd9c72dfd1614b4159fd Mon Sep 17 00:00:00 2001 From: Romain Date: Tue, 5 Oct 2021 20:39:37 +0200 Subject: Add metrics to get issues by repository (#17225) --- models/statistic.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'models') diff --git a/models/statistic.go b/models/statistic.go index c80cebba99..5e72dc713d 100644 --- a/models/statistic.go +++ b/models/statistic.go @@ -21,7 +21,8 @@ type Statistic struct { Milestone, Label, HookTask, Team, UpdateTask, Project, ProjectBoard, Attachment int64 - IssueByLabel []IssueByLabelCount + IssueByLabel []IssueByLabelCount + IssueByRepository []IssueByRepositoryCount } } @@ -31,6 +32,13 @@ type IssueByLabelCount struct { Label string } +// IssueByRepositoryCount contains the number of issue group by repository +type IssueByRepositoryCount struct { + Count int64 + OwnerName string + Repository string +} + // GetStatistic returns the database statistics func GetStatistic() (stats Statistic) { e := db.GetEngine(db.DefaultContext) @@ -58,6 +66,16 @@ func GetStatistic() (stats Statistic) { Find(&stats.Counter.IssueByLabel) } + if setting.Metrics.EnabledIssueByRepository { + stats.Counter.IssueByRepository = []IssueByRepositoryCount{} + + _ = e.Select("COUNT(*) AS count, r.owner_name, r.name AS repository"). + Join("LEFT", "repository r", "r.id=i.repo_id"). + Table("issue i"). + GroupBy("r.owner_name, r.name"). + Find(&stats.Counter.IssueByRepository) + } + issueCounts := []IssueCount{} _ = e.Select("COUNT(*) AS count, is_closed").Table("issue").GroupBy("is_closed").Find(&issueCounts) -- cgit v1.2.3