Skip to content

Commit

Permalink
Add builds per day
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Apr 18, 2023
1 parent f8b057a commit d7e5fdc
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"flag"
"fmt"
"log"
"os"
"strings"
"text/tabwriter"
"time"

units "github.com/docker/go-units"
Expand All @@ -19,11 +21,13 @@ func main() {
var (
orgName, userName, token string
since int
punchCard bool
)

flag.StringVar(&orgName, "org", "", "Organization name")
flag.StringVar(&userName, "user", "", "User name")
flag.StringVar(&token, "token", "", "GitHub token")
flag.BoolVar(&punchCard, "punch-card", false, "Show punch card with breakdown of builds per day")
flag.IntVar(&since, "since", 30, "Since when to fetch the data (in days)")

flag.Parse()
Expand Down Expand Up @@ -52,9 +56,20 @@ func main() {
longestBuild time.Duration
actors map[string]bool
conclusion map[string]int
buildsPerDay map[string]int
)

actors = make(map[string]bool)
buildsPerDay = map[string]int{
"Monday": 0,
"Tuesday": 0,
"Wednesday": 0,
"Thursday": 0,
"Friday": 0,
"Saturday": 0,
"Sunday": 0,
}

conclusion = map[string]int{
"success": 0,
"failure": 0,
Expand All @@ -73,7 +88,6 @@ func main() {
log.Printf("Fetching repos %s page %d", orgName, page)
if orgName != "" {
opts := &github.RepositoryListByOrgOptions{ListOptions: github.ListOptions{Page: page, PerPage: 100}, Type: "all"}
log.Printf("Fetching repos %s page %d", orgName, page)
repos, res, err = client.Repositories.ListByOrg(ctx, orgName, opts)
}

Expand Down Expand Up @@ -215,6 +229,10 @@ func main() {
job.GetID(), job.GetStartedAt().Format("2006-01-02 15:04:05"),
job.GetCompletedAt().Format("2006-01-02 15:04:05"),
humanDuration(dur), job.GetConclusion())

dayOfWeek := job.GetStartedAt().Time.Weekday().String()

buildsPerDay[dayOfWeek]++
}
}
}
Expand All @@ -225,6 +243,7 @@ func main() {
entity = userName
}

days := []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
fmt.Printf("\nGenerated by: https://github.com/self-actuated/actions-usage\nReport for %s - last: %d days.\n\n", entity, since)
fmt.Printf("Total repos: %d\n", len(allRepos))
fmt.Printf("Total private repos: %d\n", totalPrivate)
Expand All @@ -246,6 +265,20 @@ func main() {
fmt.Println()
fmt.Printf("Longest build: %s\n", longestBuild.Round(time.Second))
fmt.Printf("Average build time: %s\n", (allUsage / time.Duration(totalJobs)).Round(time.Second))

fmt.Println()

if punchCard {
w := tabwriter.NewWriter(os.Stdout, 15, 4, 1, ' ', tabwriter.TabIndent)
fmt.Fprintln(w, "Day\tBuilds")
for _, day := range days {
fmt.Fprintf(w, "%s\t%d\n", day, buildsPerDay[day])
}
fmt.Fprintf(w, "%s\t%d\n", "Total", totalJobs)

w.Flush()
}

}
fmt.Println()

Expand Down

0 comments on commit d7e5fdc

Please sign in to comment.