-
Notifications
You must be signed in to change notification settings - Fork 564
/
Copy pathstorage_dashboard.go
61 lines (45 loc) · 1.74 KB
/
storage_dashboard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package models
import (
"github.com/diggerhq/digger/libs/scheduler"
"time"
)
func (db *Database) GetRepoCount(orgID uint) (int64, error) {
var count int64
thirtyDaysAgo := time.Now().AddDate(0, 0, -30)
result := db.GormDB.Model(&Repo{}).
Where("organisation_id = ? AND created_at >= ?", orgID, thirtyDaysAgo).
Count(&count)
if result.Error != nil {
return 0, result.Error
}
return count, nil
}
func (db *Database) GetJobsCountThisMonth(orgID uint) (int64, error) {
var count int64
thirtyDaysAgo := time.Now().AddDate(0, 0, -30)
result := db.GormDB.Model(DiggerJob{}).
Joins("JOIN digger_batches ON digger_jobs.batch_id = digger_batches.id").
Joins("JOIN github_app_installation_links ON digger_batches.github_installation_id = github_app_installation_links.github_installation_id").
Joins("JOIN organisations ON github_app_installation_links.organisation_id = organisations.id").
Where("digger_jobs.created_at >= ?", thirtyDaysAgo).
Count(&count)
if result.Error != nil {
return 0, result.Error
}
return count, nil
}
func (db *Database) GetSuccessfulJobsCountThisMonth(orgID uint) (int64, error) {
var count int64
thirtyDaysAgo := time.Now().AddDate(0, 0, -30)
result := db.GormDB.Model(DiggerJob{}).
Joins("JOIN digger_batches ON digger_jobs.batch_id = digger_batches.id").
Joins("JOIN github_app_installation_links ON digger_batches.github_installation_id = github_app_installation_links.github_installation_id").
Joins("JOIN organisations ON github_app_installation_links.organisation_id = organisations.id").
Where("digger_jobs.created_at >= ?", thirtyDaysAgo).
Where("digger_jobs.status = ?", scheduler.DiggerJobSucceeded).
Count(&count)
if result.Error != nil {
return 0, result.Error
}
return count, nil
}