refactor #10
1 changed files with 26 additions and 9 deletions
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue