Add metrics to get issues by repository (#17225)

This commit is contained in:
Romain 2021-10-05 20:39:37 +02:00 committed by GitHub
parent 760d61b411
commit 987152ba40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 35 deletions

View file

@ -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)