@@ -19,19 +19,29 @@ import (
1919func main () {
2020
2121 var (
22- orgName , userName , token string
23- since int
24- punchCard bool
22+ orgName , userName , token , tokenFile string
23+ days int
24+ punchCard bool
2525 )
2626
2727 flag .StringVar (& orgName , "org" , "" , "Organization name" )
2828 flag .StringVar (& userName , "user" , "" , "User name" )
2929 flag .StringVar (& token , "token" , "" , "GitHub token" )
30+ flag .StringVar (& tokenFile , "token-file" , "" , "Path to the file containing the GitHub token" )
31+
3032 flag .BoolVar (& punchCard , "punch-card" , false , "Show punch card with breakdown of builds per day" )
31- flag .IntVar (& since , "since " , 30 , "Since when to fetch the data (in days) " )
33+ flag .IntVar (& days , "days " , 30 , "How many days of data to query from the GitHub API " )
3234
3335 flag .Parse ()
3436
37+ if len (tokenFile ) > 0 {
38+ tokenBytes , err := os .ReadFile (tokenFile )
39+ if err != nil {
40+ log .Fatal (err )
41+ }
42+ token = strings .TrimSpace (string (tokenBytes ))
43+ }
44+
3545 auth := oauth2 .NewClient (context .Background (), oauth2 .StaticTokenSource (
3646 & oauth2.Token {AccessToken : token },
3747 ))
@@ -44,7 +54,7 @@ func main() {
4454 }
4555
4656 client := github .NewClient (auth )
47- created := time .Now ().AddDate (0 , 0 , - since )
57+ created := time .Now ().AddDate (0 , 0 , - days )
4858 format := "2006-01-02"
4959 createdQuery := ">=" + created .Format (format )
5060
@@ -77,7 +87,7 @@ func main() {
7787 "skipped" : 0 ,
7888 }
7989
80- fmt .Printf ("Fetching last %d days of data (created>=%s)\n " , since , created .Format ("2006-01-02" ))
90+ fmt .Printf ("Fetching last %d days of data (created>=%s)\n " , days , created .Format ("2006-01-02" ))
8191
8292 var repos , allRepos []* github.Repository
8393 var res * github.Response
@@ -243,8 +253,8 @@ func main() {
243253 entity = userName
244254 }
245255
246- days := []string {"Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday" }
247- fmt .Printf ("\n Generated by: https://github.com/self-actuated/actions-usage\n Report for %s - last: %d days.\n \n " , entity , since )
256+ daysOfWEek := []string {"Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday" }
257+ fmt .Printf ("\n Generated by: https://github.com/self-actuated/actions-usage\n Report for %s - last: %d days.\n \n " , entity , days )
248258 fmt .Printf ("Total repos: %d\n " , len (allRepos ))
249259 fmt .Printf ("Total private repos: %d\n " , totalPrivate )
250260 fmt .Printf ("Total public repos: %d\n " , totalPublic )
@@ -271,7 +281,7 @@ func main() {
271281 if punchCard {
272282 w := tabwriter .NewWriter (os .Stdout , 15 , 4 , 1 , ' ' , tabwriter .TabIndent )
273283 fmt .Fprintln (w , "Day\t Builds" )
274- for _ , day := range days {
284+ for _ , day := range daysOfWEek {
275285 fmt .Fprintf (w , "%s\t %d\n " , day , buildsPerDay [day ])
276286 }
277287 fmt .Fprintf (w , "%s\t %d\n " , "Total" , totalJobs )
0 commit comments