refactor #10

Merged
mfocko merged 2 commits from refactor into main 2021-12-11 17:26:36 +01:00
Showing only changes of commit 98de5e4c17 - Show all commits

View file

@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"sort"
"strings"
"code.gitea.io/sdk/gitea"
@ -29,37 +30,53 @@ var (
})
core.ExitOnError("Couldn't list the pull requests", err)
GetStats(client, milestone, prs)
GetStats(prs)
},
}
)
func GetStats(client *gitea.Client, milestone *gitea.Milestone, prs []*gitea.PullRequest) {
graded := 0
func ParseHistogram(prs []*gitea.PullRequest) map[string]int {
histogram := make(map[string]int)
for _, pr := range prs {
for _, label := range pr.Labels {
if strings.HasPrefix(label.Name, "grade:") {
grade := strings.Split(label.Name, ":")[1]
histogram[grade] += 1
graded += 1
break
}
}
}
for grade, count := range histogram {
return histogram
}
func SortedKeys(histogram map[string]int) []string {
grades := make([]string, 0, len(histogram))
for grade := range histogram {
grades = append(grades, grade)
}
sort.Strings(grades)
return grades
}
func GetStats(prs []*gitea.PullRequest) {
histogram := ParseHistogram(prs)
grades := SortedKeys(histogram)
graded := 0
for _, grade := range grades {
count := histogram[grade]
if (count == 0) {
continue
}
fmt.Printf("%s: %d\n", grade, count)
graded += count
fmt.Printf(" %s: %2d\n", grade, count)
}
if (len(prs) - graded > 0) {
fmt.Printf("ungraded: %d\n", len(prs) - graded)
fmt.Println("--------")
fmt.Printf("TODO: %2d\n", len(prs) - graded)
}
}