Skip to content

Commit 4097247

Browse files
committed
Rename -since to -days and add -token-file flag
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent d7e5fdc commit 4097247

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ sudo mv $HOME/.arkade/bin/actions-usage /usr/local/bin/
3939
## Output
4040

4141
```bash
42-
actions-usage --org openfaas --token $(cat ~/pat.txt) --days 28
42+
actions-usage --org openfaas --token-file ~/pat.txt --days 28
4343

4444
Usage report generated by self-actuated/actions-usage.
4545

@@ -59,7 +59,7 @@ Total usage: 8h24m21s (504 mins)
5959
As a user:
6060

6161
```bash
62-
actions-usage --user alexellis --token $(cat ~/pat.txt)
62+
actions-usage --user alexellis --token-file ~/pat.txt
6363
```
6464

6565
## Development
@@ -70,7 +70,7 @@ All changes must be proposed with an Issue prior to working on them or sending a
7070
git clone https://github.com/actuated/actions-usage
7171
cd actions-usage
7272

73-
go run . --org actuated-samples --token $(cat ~/pat.txt)
73+
go run . --org actuated-samples --token-file ~/pat.txt
7474
```
7575

7676
## Author

main.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,29 @@ import (
1919
func 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("\nGenerated by: https://github.com/self-actuated/actions-usage\nReport for %s - last: %d days.\n\n", entity, since)
256+
daysOfWEek := []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
257+
fmt.Printf("\nGenerated by: https://github.com/self-actuated/actions-usage\nReport 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\tBuilds")
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

Comments
 (0)