diff --git a/main.go b/main.go index 5b2d2ab..51f9c1c 100644 --- a/main.go +++ b/main.go @@ -51,9 +51,16 @@ func main() { totalPublic int longestBuild time.Duration actors map[string]bool + conclusion map[string]int ) actors = make(map[string]bool) + conclusion = map[string]int{ + "success": 0, + "failure": 0, + "cancelled": 0, + "skipped": 0, + } fmt.Printf("Fetching last %d days of data (created>=%s)\n", since, created.Format("2006-01-02")) @@ -177,6 +184,12 @@ func main() { if dur > longestBuild { longestBuild = dur } + + if _, ok := conclusion[job.GetConclusion()]; !ok { + conclusion[job.GetConclusion()] = 0 + } + + conclusion[job.GetConclusion()]++ } workflowJobs = append(workflowJobs, jobs.Jobs...) @@ -207,7 +220,12 @@ func main() { } } - fmt.Println("\nUsage report generated by self-actuated/actions-usage.\n") + entity := orgName + if len(orgName) == 0 { + entity = userName + } + + 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) fmt.Printf("Total public repos: %d\n", totalPublic) @@ -216,11 +234,24 @@ func main() { 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)) + + if totalJobs > 0 { + fmt.Println() + fmt.Printf("Success: %d/%d\n", conclusion["success"], totalJobs) + fmt.Printf("Failure: %d/%d\n", conclusion["failure"], totalJobs) + fmt.Printf("Cancelled: %d/%d\n", conclusion["cancelled"], totalJobs) + if conclusion["skipped"] > 0 { + fmt.Printf("Skipped: %d/%d\n", conclusion["skipped"], totalJobs) + } + 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() mins := fmt.Sprintf("%.0f mins", allUsage.Minutes()) fmt.Printf("Total usage: %s (%s)\n", allUsage.String(), mins) + fmt.Println() } // types.HumanDuration fixes a long string for a value < 1s