diff --git a/main.go b/main.go index e3542b5..5b2d2ab 100644 --- a/main.go +++ b/main.go @@ -49,8 +49,12 @@ func main() { totalJobs int totalPrivate int totalPublic int + longestBuild time.Duration + actors map[string]bool ) + actors = make(map[string]bool) + fmt.Printf("Fetching last %d days of data (created>=%s)\n", since, created.Format("2006-01-02")) var repos, allRepos []*github.Repository @@ -154,6 +158,9 @@ func main() { log.Printf("Fetching jobs for: run ID: %d, startedAt: %s, conclusion: %s", run.GetID(), run.GetRunStartedAt().Format("2006-01-02 15:04:05"), run.GetConclusion()) workflowJobs := []*github.WorkflowJob{} + if a := run.GetActor(); a != nil { + actors[a.GetLogin()] = true + } page := 0 for { log.Printf("Fetching jobs for: %d, page %d", run.GetID(), page) @@ -165,6 +172,13 @@ func main() { log.Fatal(err) } + for _, job := range jobs.Jobs { + dur := job.GetCompletedAt().Time.Sub(job.GetStartedAt().Time) + if dur > longestBuild { + longestBuild = dur + } + } + workflowJobs = append(workflowJobs, jobs.Jobs...) if len(jobs.Jobs) == 0 { @@ -193,12 +207,18 @@ func main() { } } + fmt.Println("\nUsage report generated by self-actuated/actions-usage.\n") fmt.Printf("Total repos: %d\n", len(allRepos)) fmt.Printf("Total private repos: %d\n", totalPrivate) fmt.Printf("Total public repos: %d\n", totalPublic) fmt.Println() fmt.Printf("Total workflow runs: %d\n", totalRuns) fmt.Printf("Total workflow jobs: %d\n", totalJobs) + fmt.Println() + fmt.Printf("Total users: %d\n", len(actors)) + fmt.Printf("Longest build: %s\n", longestBuild.Round(time.Second)) + fmt.Printf("Average build time: %s\n", (allUsage / time.Duration(totalJobs)).Round(time.Second)) + mins := fmt.Sprintf("%.0f mins", allUsage.Minutes()) fmt.Printf("Total usage: %s (%s)\n", allUsage.String(), mins) }