JOJ3/internal/parser/clangtidy/score.go
张泊明518370910136 9e1ecf164b
Some checks failed
build / trigger-build-image (push) Blocked by required conditions
build / build (push) Has been cancelled
submodules sync / sync (push) Has been cancelled
feat(parser/clangtidy): summary by category
2024-11-01 05:26:06 -04:00

51 lines
1.1 KiB
Go

package clangtidy
import (
"fmt"
"sort"
"strings"
)
func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
score := conf.Score
comment := "### Test results summary\n\n"
categoryCount := map[string]int{}
for _, jsonMessage := range jsonMessages {
// checkName is commas separated string here
checkName := jsonMessage.CheckName
for _, match := range conf.Matches {
for _, keyword := range match.Keywords {
if strings.Contains(checkName, keyword) {
score -= match.Score
}
}
}
checkNames := strings.Split(checkName, ",")
for _, checkName := range checkNames {
parts := strings.Split(checkName, "-")
if len(parts) > 0 {
category := parts[0]
categoryCount[category] += 1
}
}
}
type kv struct {
Key string
Value int
}
var ss []kv
for k, v := range categoryCount {
ss = append(ss, kv{k, v})
}
sort.Slice(ss, func(i, j int) bool {
if ss[i].Value == ss[j].Value {
return ss[i].Key < ss[j].Key
}
return ss[i].Value > ss[j].Value
})
for i, kv := range ss {
comment += fmt.Sprintf("%d. %s: %d\n", i+1, kv.Key, kv.Value)
}
return score, comment
}