refactor: Stats
• Remove unused parameters from functions • Decompose functions where possible Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
0dbfd6e849
commit
98de5e4c17
1 changed files with 26 additions and 9 deletions
|
@ -2,6 +2,7 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
|
@ -29,37 +30,53 @@ var (
|
||||||
})
|
})
|
||||||
core.ExitOnError("Couldn't list the pull requests", err)
|
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) {
|
func ParseHistogram(prs []*gitea.PullRequest) map[string]int {
|
||||||
graded := 0
|
|
||||||
histogram := make(map[string]int)
|
histogram := make(map[string]int)
|
||||||
|
|
||||||
for _, pr := range prs {
|
for _, pr := range prs {
|
||||||
for _, label := range pr.Labels {
|
for _, label := range pr.Labels {
|
||||||
if strings.HasPrefix(label.Name, "grade:") {
|
if strings.HasPrefix(label.Name, "grade:") {
|
||||||
grade := strings.Split(label.Name, ":")[1]
|
grade := strings.Split(label.Name, ":")[1]
|
||||||
|
|
||||||
histogram[grade] += 1
|
histogram[grade] += 1
|
||||||
graded += 1
|
|
||||||
|
|
||||||
break
|
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) {
|
if (count == 0) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%s: %d\n", grade, count)
|
graded += count
|
||||||
|
fmt.Printf(" %s: %2d\n", grade, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len(prs) - graded > 0) {
|
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