55 "flag"
66 "fmt"
77 "log"
8+ "os"
89 "strings"
10+ "text/tabwriter"
911 "time"
1012
1113 units "github.com/docker/go-units"
@@ -19,11 +21,13 @@ func main() {
1921 var (
2022 orgName , userName , token string
2123 since int
24+ punchCard bool
2225 )
2326
2427 flag .StringVar (& orgName , "org" , "" , "Organization name" )
2528 flag .StringVar (& userName , "user" , "" , "User name" )
2629 flag .StringVar (& token , "token" , "" , "GitHub token" )
30+ flag .BoolVar (& punchCard , "punch-card" , false , "Show punch card with breakdown of builds per day" )
2731 flag .IntVar (& since , "since" , 30 , "Since when to fetch the data (in days)" )
2832
2933 flag .Parse ()
@@ -52,9 +56,20 @@ func main() {
5256 longestBuild time.Duration
5357 actors map [string ]bool
5458 conclusion map [string ]int
59+ buildsPerDay map [string ]int
5560 )
5661
5762 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+
5873 conclusion = map [string ]int {
5974 "success" : 0 ,
6075 "failure" : 0 ,
@@ -73,7 +88,6 @@ func main() {
7388 log .Printf ("Fetching repos %s page %d" , orgName , page )
7489 if orgName != "" {
7590 opts := & github.RepositoryListByOrgOptions {ListOptions : github.ListOptions {Page : page , PerPage : 100 }, Type : "all" }
76- log .Printf ("Fetching repos %s page %d" , orgName , page )
7791 repos , res , err = client .Repositories .ListByOrg (ctx , orgName , opts )
7892 }
7993
@@ -215,6 +229,10 @@ func main() {
215229 job .GetID (), job .GetStartedAt ().Format ("2006-01-02 15:04:05" ),
216230 job .GetCompletedAt ().Format ("2006-01-02 15:04:05" ),
217231 humanDuration (dur ), job .GetConclusion ())
232+
233+ dayOfWeek := job .GetStartedAt ().Time .Weekday ().String ()
234+
235+ buildsPerDay [dayOfWeek ]++
218236 }
219237 }
220238 }
@@ -225,6 +243,7 @@ func main() {
225243 entity = userName
226244 }
227245
246+ days := []string {"Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday" }
228247 fmt .Printf ("\n Generated by: https://github.com/self-actuated/actions-usage\n Report for %s - last: %d days.\n \n " , entity , since )
229248 fmt .Printf ("Total repos: %d\n " , len (allRepos ))
230249 fmt .Printf ("Total private repos: %d\n " , totalPrivate )
@@ -246,6 +265,20 @@ func main() {
246265 fmt .Println ()
247266 fmt .Printf ("Longest build: %s\n " , longestBuild .Round (time .Second ))
248267 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+
249282 }
250283 fmt .Println ()
251284
0 commit comments