Compare commits
No commits in common. "a6353dfed8e703e84b308b07ebcc4fcc7cf2a9f7" and "198fcc3c86ad72176c963f5c24136b7106dea192" have entirely different histories.
a6353dfed8
...
198fcc3c86
|
@ -41,9 +41,11 @@ func setupSlog() {
|
||||||
var (
|
var (
|
||||||
rootDir string
|
rootDir string
|
||||||
repoSize float64
|
repoSize float64
|
||||||
|
localList string
|
||||||
checkFileNameList string
|
checkFileNameList string
|
||||||
checkFileSumList string
|
checkFileSumList string
|
||||||
metaFile []string
|
metaFile []string
|
||||||
|
gitWhitelist []string
|
||||||
confPath string
|
confPath string
|
||||||
showVersion *bool
|
showVersion *bool
|
||||||
Version string
|
Version string
|
||||||
|
@ -53,9 +55,13 @@ func init() {
|
||||||
showVersion = flag.Bool("version", false, "print current version")
|
showVersion = flag.Bool("version", false, "print current version")
|
||||||
flag.StringVar(&rootDir, "root", ".", "root dir for forbidden files check")
|
flag.StringVar(&rootDir, "root", ".", "root dir for forbidden files check")
|
||||||
flag.Float64Var(&repoSize, "repoSize", 2, "maximum size of the repo in MiB")
|
flag.Float64Var(&repoSize, "repoSize", 2, "maximum size of the repo in MiB")
|
||||||
|
// TODO: remove localList, it is only for backward compatibility now
|
||||||
|
flag.StringVar(&localList, "localList", "", "local file list for non-ascii file check")
|
||||||
flag.StringVar(&checkFileNameList, "checkFileNameList", "", "comma-separated list of files to check")
|
flag.StringVar(&checkFileNameList, "checkFileNameList", "", "comma-separated list of files to check")
|
||||||
flag.StringVar(&checkFileSumList, "checkFileSumList", "", "comma-separated list of expected checksums")
|
flag.StringVar(&checkFileSumList, "checkFileSumList", "", "comma-separated list of expected checksums")
|
||||||
parseMultiValueFlag(&metaFile, "meta", "meta files to check")
|
parseMultiValueFlag(&metaFile, "meta", "meta files to check")
|
||||||
|
// TODO: remove gitWhitelist, it is only for backward compatibility now
|
||||||
|
parseMultiValueFlag(&gitWhitelist, "whitelist", "[DEPRECATED] will be ignored")
|
||||||
flag.StringVar(&confPath, "confPath", "", "path to conf file for teapot check")
|
flag.StringVar(&confPath, "confPath", "", "path to conf file for teapot check")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +109,7 @@ func main() {
|
||||||
slog.Info("start repo-health-checker", "version", Version)
|
slog.Info("start repo-health-checker", "version", Version)
|
||||||
slog.Debug("cli args",
|
slog.Debug("cli args",
|
||||||
"repoSize", repoSize,
|
"repoSize", repoSize,
|
||||||
|
"localList", localList,
|
||||||
"checkFileNameList", checkFileNameList,
|
"checkFileNameList", checkFileNameList,
|
||||||
"checkFileSumList", checkFileSumList,
|
"checkFileSumList", checkFileSumList,
|
||||||
"meta", metaFile,
|
"meta", metaFile,
|
||||||
|
|
|
@ -331,6 +331,7 @@ func MatchGroups(conf *Conf, conventionalCommit *ConventionalCommit) []string {
|
||||||
seen := make(map[string]bool)
|
seen := make(map[string]bool)
|
||||||
keywords := []string{}
|
keywords := []string{}
|
||||||
loweredCommitGroup := strings.ToLower(conventionalCommit.Group)
|
loweredCommitGroup := strings.ToLower(conventionalCommit.Group)
|
||||||
|
loweredCommitDescription := strings.ToLower(conventionalCommit.Description)
|
||||||
for i, stage := range conf.Stage.Stages {
|
for i, stage := range conf.Stage.Stages {
|
||||||
if loweredCommitGroup == "all" {
|
if loweredCommitGroup == "all" {
|
||||||
conf.Stage.Stages[i].Group = ""
|
conf.Stage.Stages[i].Group = ""
|
||||||
|
@ -347,7 +348,8 @@ func MatchGroups(conf *Conf, conventionalCommit *ConventionalCommit) []string {
|
||||||
slog.Info("group keywords from stages", "keywords", keywords)
|
slog.Info("group keywords from stages", "keywords", keywords)
|
||||||
groups := []string{}
|
groups := []string{}
|
||||||
for _, keyword := range keywords {
|
for _, keyword := range keywords {
|
||||||
if strings.Contains(loweredCommitGroup, keyword) {
|
if strings.Contains(loweredCommitGroup, keyword) ||
|
||||||
|
strings.Contains(loweredCommitDescription, keyword) { // TODO: remove me
|
||||||
groups = append(groups, keyword)
|
groups = append(groups, keyword)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
type Match struct {
|
type Match struct {
|
||||||
Keywords []string
|
Keywords []string
|
||||||
|
Severity []string // TODO: remove me
|
||||||
Score int
|
Score int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package cppcheck
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -19,9 +20,68 @@ const (
|
||||||
UNKNOWN
|
UNKNOWN
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func severityFromString(severityString string) (Severity, error) {
|
||||||
|
switch severityString {
|
||||||
|
case "error":
|
||||||
|
return ERROR, nil
|
||||||
|
case "warning":
|
||||||
|
return WARNING, nil
|
||||||
|
case "portability":
|
||||||
|
return PORTABILITY, nil
|
||||||
|
case "performance":
|
||||||
|
return PERFORMANCE, nil
|
||||||
|
case "style":
|
||||||
|
return STYLE, nil
|
||||||
|
case "information":
|
||||||
|
return INFORMATION, nil
|
||||||
|
case "debug":
|
||||||
|
return DEBUG, nil
|
||||||
|
default:
|
||||||
|
return UNKNOWN, fmt.Errorf("unknown severity type \"%s\" for cppcheck", severityString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GetResult(records []Record, conf Conf) (string, int, error) {
|
func GetResult(records []Record, conf Conf) (string, int, error) {
|
||||||
score := conf.Score
|
score := conf.Score
|
||||||
comment := "### Test results summary\n\n"
|
comment := "### Test results summary\n\n"
|
||||||
|
var severityCounts [UNKNOWN + 1]int
|
||||||
|
// TODO: remove me
|
||||||
|
var severityScore [UNKNOWN + 1]int
|
||||||
|
for _, match := range conf.Matches {
|
||||||
|
severities := match.Severity
|
||||||
|
score := match.Score
|
||||||
|
for _, severityString := range severities {
|
||||||
|
severity, err := severityFromString(severityString)
|
||||||
|
if err != nil {
|
||||||
|
return "", 0, err
|
||||||
|
}
|
||||||
|
severityScore[int(severity)] = score
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalSeverityScore := 0
|
||||||
|
for _, score := range severityScore {
|
||||||
|
totalSeverityScore += score
|
||||||
|
}
|
||||||
|
if totalSeverityScore != 0 {
|
||||||
|
for _, record := range records {
|
||||||
|
if record.File == "nofile" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
severity, err := severityFromString(record.Severity)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("parse severity", "error", err)
|
||||||
|
}
|
||||||
|
severityCounts[int(severity)] += 1
|
||||||
|
score -= severityScore[int(severity)]
|
||||||
|
}
|
||||||
|
comment += fmt.Sprintf("1. error: %d\n", severityCounts[0])
|
||||||
|
comment += fmt.Sprintf("2. warning: %d\n", severityCounts[1])
|
||||||
|
comment += fmt.Sprintf("3. portability: %d\n", severityCounts[2])
|
||||||
|
comment += fmt.Sprintf("4. performance: %d\n", severityCounts[3])
|
||||||
|
comment += fmt.Sprintf("5. style: %d\n", severityCounts[4])
|
||||||
|
comment += fmt.Sprintf("6. information: %d\n", severityCounts[5])
|
||||||
|
comment += fmt.Sprintf("7. debug: %d\n", severityCounts[6])
|
||||||
|
}
|
||||||
matchCount := make(map[string]int)
|
matchCount := make(map[string]int)
|
||||||
scoreChange := make(map[string]int)
|
scoreChange := make(map[string]int)
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
|
|
|
@ -2,11 +2,14 @@ package cpplint
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||||
|
"github.com/joint-online-judge/JOJ3/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Match struct {
|
type Match struct {
|
||||||
|
@ -31,6 +34,7 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||||
regexMatches := re.FindAllStringSubmatch(stderr, -1)
|
regexMatches := re.FindAllStringSubmatch(stderr, -1)
|
||||||
score := conf.Score
|
score := conf.Score
|
||||||
comment := "### Test results summary\n\n"
|
comment := "### Test results summary\n\n"
|
||||||
|
categoryCount := make(map[string]int)
|
||||||
matchCount := make(map[string]int)
|
matchCount := make(map[string]int)
|
||||||
scoreChange := make(map[string]int)
|
scoreChange := make(map[string]int)
|
||||||
for _, regexMatch := range regexMatches {
|
for _, regexMatch := range regexMatches {
|
||||||
|
@ -45,6 +49,24 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||||
// }
|
// }
|
||||||
// message := regexMatch[3]
|
// message := regexMatch[3]
|
||||||
category := regexMatch[4]
|
category := regexMatch[4]
|
||||||
|
// TODO: remove me
|
||||||
|
if len(conf.Matches) == 0 {
|
||||||
|
confidence, err := strconv.Atoi(regexMatch[5])
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("parse confidence", "error", err)
|
||||||
|
return stage.ParserResult{
|
||||||
|
Score: 0,
|
||||||
|
Comment: fmt.Sprintf("Unexpected parser error: %s.", err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
score -= confidence
|
||||||
|
}
|
||||||
|
parts := strings.Split(category, "/")
|
||||||
|
if len(parts) > 0 {
|
||||||
|
category := parts[0]
|
||||||
|
categoryCount[category] += 1
|
||||||
|
}
|
||||||
|
// TODO: remove me ends
|
||||||
for _, match := range conf.Matches {
|
for _, match := range conf.Matches {
|
||||||
for _, keyword := range match.Keywords {
|
for _, keyword := range match.Keywords {
|
||||||
if strings.Contains(category, keyword) {
|
if strings.Contains(category, keyword) {
|
||||||
|
@ -55,6 +77,18 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: remove me
|
||||||
|
sortedMap := utils.SortMap(categoryCount,
|
||||||
|
func(i, j utils.Pair[string, int]) bool {
|
||||||
|
if i.Value == j.Value {
|
||||||
|
return i.Key < j.Key
|
||||||
|
}
|
||||||
|
return i.Value > j.Value
|
||||||
|
})
|
||||||
|
for i, kv := range sortedMap {
|
||||||
|
comment += fmt.Sprintf("%d. %s: %d\n", i+1, kv.Key, kv.Value)
|
||||||
|
}
|
||||||
|
// TODO: remove me ends
|
||||||
type Result struct {
|
type Result struct {
|
||||||
Keyword string
|
Keyword string
|
||||||
Count int
|
Count int
|
||||||
|
|
|
@ -10,12 +10,14 @@ import (
|
||||||
|
|
||||||
type Match struct {
|
type Match struct {
|
||||||
Keywords []string
|
Keywords []string
|
||||||
|
Keyword string // TODO: remove me
|
||||||
Score int
|
Score int
|
||||||
MaxMatchCount int
|
MaxMatchCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
Score int
|
Score int
|
||||||
|
FullScore int // TODO: remove me
|
||||||
Files []string
|
Files []string
|
||||||
ForceQuitOnDeduct bool `default:"false"`
|
ForceQuitOnDeduct bool `default:"false"`
|
||||||
Matches []Match
|
Matches []Match
|
||||||
|
@ -81,6 +83,17 @@ func (*Keyword) Run(results []stage.ExecutorResult, confAny any) (
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, true, err
|
return nil, true, err
|
||||||
}
|
}
|
||||||
|
// TODO: remove me on Matches.Keyword field removed
|
||||||
|
for i := range conf.Matches {
|
||||||
|
match := &conf.Matches[i]
|
||||||
|
if match.Keyword != "" && len(match.Keywords) == 0 {
|
||||||
|
match.Keywords = []string{match.Keyword}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: remove me on FullScore field removed
|
||||||
|
if conf.FullScore != 0 && conf.Score == 0 {
|
||||||
|
conf.Score = conf.FullScore
|
||||||
|
}
|
||||||
var res []stage.ParserResult
|
var res []stage.ParserResult
|
||||||
forceQuit := false
|
forceQuit := false
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user