fix: clangtidy parser get result
This commit is contained in:
parent
cab7861494
commit
bb63cb65ba
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Match struct {
|
type Match struct {
|
||||||
Keyword []string
|
Keywords []string
|
||||||
Score int
|
Score int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,9 +41,10 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
score, comment := GetResult(formattedMessages, conf)
|
||||||
return stage.ParserResult{
|
return stage.ParserResult{
|
||||||
Score: GetScore(formattedMessages, conf),
|
Score: score,
|
||||||
Comment: GetComment(formattedMessages),
|
Comment: comment,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,32 +5,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func contains(arr []string, element string) bool {
|
func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
|
||||||
for i := range arr {
|
score := conf.Score
|
||||||
// TODO: The keyword in json report might also be an array, need to split it
|
comment := "### Test results summary\n\n"
|
||||||
if strings.Contains(arr[i], element) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetScore(jsonMessages []JsonMessage, conf Conf) int {
|
|
||||||
fullmark := conf.Score
|
|
||||||
for _, jsonMessage := range jsonMessages {
|
|
||||||
keyword := jsonMessage.CheckName
|
|
||||||
for _, match := range conf.Matches {
|
|
||||||
if contains(match.Keyword, keyword) {
|
|
||||||
fullmark -= match.Score
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fullmark
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetComment(jsonMessages []JsonMessage) string {
|
|
||||||
res := "### Test results summary\n\n"
|
|
||||||
keys := [...]string{
|
keys := [...]string{
|
||||||
"codequality-unchecked-malloc-result",
|
"codequality-unchecked-malloc-result",
|
||||||
"codequality-no-global-variables",
|
"codequality-no-global-variables",
|
||||||
|
@ -56,22 +33,29 @@ func GetComment(jsonMessages []JsonMessage) string {
|
||||||
mapping[key] = 0
|
mapping[key] = 0
|
||||||
}
|
}
|
||||||
for _, jsonMessage := range jsonMessages {
|
for _, jsonMessage := range jsonMessages {
|
||||||
keyword := jsonMessage.CheckName
|
checkName := jsonMessage.CheckName
|
||||||
flag := true
|
for _, match := range conf.Matches {
|
||||||
|
for _, keyword := range match.Keywords {
|
||||||
|
// TODO: The keyword in json report might also be an array, need to split it
|
||||||
|
if strings.Contains(checkName, keyword) {
|
||||||
|
score -= match.Score
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
listed := false
|
||||||
for key := range mapping {
|
for key := range mapping {
|
||||||
if strings.Contains(keyword, key) {
|
if strings.Contains(checkName, key) {
|
||||||
mapping[key] += 1
|
mapping[key] += 1
|
||||||
flag = false
|
listed = true
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if flag {
|
if !listed {
|
||||||
mapping["others"] += 1
|
mapping["others"] += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, key := range keys {
|
for i, key := range keys {
|
||||||
res = fmt.Sprintf("%s%d. %s: %d\n", res, i+1, key, mapping[key])
|
comment = fmt.Sprintf("%s%d. %s: %d\n", comment, i+1, key, mapping[key])
|
||||||
}
|
}
|
||||||
return res
|
return score, comment
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user