mirror of
https://github.com/go-gitea/gitea.git
synced 2024-05-11 05:55:29 +00:00
Add metrics to get issues by repository (#17225)
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user