5
5
"flag"
6
6
"fmt"
7
7
"log"
8
+ "os"
8
9
"strings"
10
+ "text/tabwriter"
9
11
"time"
10
12
11
13
units "github.com/docker/go-units"
@@ -19,11 +21,13 @@ func main() {
19
21
var (
20
22
orgName , userName , token string
21
23
since int
24
+ punchCard bool
22
25
)
23
26
24
27
flag .StringVar (& orgName , "org" , "" , "Organization name" )
25
28
flag .StringVar (& userName , "user" , "" , "User name" )
26
29
flag .StringVar (& token , "token" , "" , "GitHub token" )
30
+ flag .BoolVar (& punchCard , "punch-card" , false , "Show punch card with breakdown of builds per day" )
27
31
flag .IntVar (& since , "since" , 30 , "Since when to fetch the data (in days)" )
28
32
29
33
flag .Parse ()
@@ -52,9 +56,20 @@ func main() {
52
56
longestBuild time.Duration
53
57
actors map [string ]bool
54
58
conclusion map [string ]int
59
+ buildsPerDay map [string ]int
55
60
)
56
61
57
62
actors = make (map [string ]bool )
63
+ buildsPerDay = map [string ]int {
64
+ "Monday" : 0 ,
65
+ "Tuesday" : 0 ,
66
+ "Wednesday" : 0 ,
67
+ "Thursday" : 0 ,
68
+ "Friday" : 0 ,
69
+ "Saturday" : 0 ,
70
+ "Sunday" : 0 ,
71
+ }
72
+
58
73
conclusion = map [string ]int {
59
74
"success" : 0 ,
60
75
"failure" : 0 ,
@@ -73,7 +88,6 @@ func main() {
73
88
log .Printf ("Fetching repos %s page %d" , orgName , page )
74
89
if orgName != "" {
75
90
opts := & github.RepositoryListByOrgOptions {ListOptions : github.ListOptions {Page : page , PerPage : 100 }, Type : "all" }
76
- log .Printf ("Fetching repos %s page %d" , orgName , page )
77
91
repos , res , err = client .Repositories .ListByOrg (ctx , orgName , opts )
78
92
}
79
93
@@ -215,6 +229,10 @@ func main() {
215
229
job .GetID (), job .GetStartedAt ().Format ("2006-01-02 15:04:05" ),
216
230
job .GetCompletedAt ().Format ("2006-01-02 15:04:05" ),
217
231
humanDuration (dur ), job .GetConclusion ())
232
+
233
+ dayOfWeek := job .GetStartedAt ().Time .Weekday ().String ()
234
+
235
+ buildsPerDay [dayOfWeek ]++
218
236
}
219
237
}
220
238
}
@@ -225,6 +243,7 @@ func main() {
225
243
entity = userName
226
244
}
227
245
246
+ days := []string {"Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday" }
228
247
fmt .Printf ("\n Generated by: https://github.com/self-actuated/actions-usage\n Report for %s - last: %d days.\n \n " , entity , since )
229
248
fmt .Printf ("Total repos: %d\n " , len (allRepos ))
230
249
fmt .Printf ("Total private repos: %d\n " , totalPrivate )
@@ -246,6 +265,20 @@ func main() {
246
265
fmt .Println ()
247
266
fmt .Printf ("Longest build: %s\n " , longestBuild .Round (time .Second ))
248
267
fmt .Printf ("Average build time: %s\n " , (allUsage / time .Duration (totalJobs )).Round (time .Second ))
268
+
269
+ fmt .Println ()
270
+
271
+ if punchCard {
272
+ w := tabwriter .NewWriter (os .Stdout , 15 , 4 , 1 , ' ' , tabwriter .TabIndent )
273
+ fmt .Fprintln (w , "Day\t Builds" )
274
+ for _ , day := range days {
275
+ fmt .Fprintf (w , "%s\t %d\n " , day , buildsPerDay [day ])
276
+ }
277
+ fmt .Fprintf (w , "%s\t %d\n " , "Total" , totalJobs )
278
+
279
+ w .Flush ()
280
+ }
281
+
249
282
}
250
283
fmt .Println ()
251
284
0 commit comments