chore(parser): make unnecessary methods private
This commit is contained in:
parent
1e75ab1c6e
commit
b4e706f8e9
|
@ -34,7 +34,7 @@ func GetCommitMsg() (msg string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func ParseConventionalCommit(commit string) (*ConventionalCommit, error) {
|
||||
func parseConventionalCommit(commit string) (*ConventionalCommit, error) {
|
||||
re := regexp.MustCompile(`(?s)^(\w+)(\(([^)]+)\))?!?: (.+?(\[([^\]]+)\])?)(\n\n(.+?))?(\n\n(.+))?$`)
|
||||
matches := re.FindStringSubmatch(strings.TrimSpace(commit))
|
||||
if matches == nil {
|
||||
|
@ -91,7 +91,7 @@ func parseMsg(confRoot, confName, msg, tag string) (
|
|||
confPath string, conventionalCommit *ConventionalCommit, err error,
|
||||
) {
|
||||
slog.Info("parse msg", "msg", msg)
|
||||
conventionalCommit, err = ParseConventionalCommit(msg)
|
||||
conventionalCommit, err = parseConventionalCommit(msg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ func TestParseConventionalCommit(t *testing.T) {
|
|||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := ParseConventionalCommit(tt.commit)
|
||||
got, err := parseConventionalCommit(tt.commit)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("ParseConventionalCommit() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||
)
|
||||
|
||||
func generateResult(
|
||||
func (e *Local) generateResult(
|
||||
err error,
|
||||
processState *os.ProcessState,
|
||||
runTime time.Duration,
|
||||
|
@ -134,7 +134,7 @@ func (e *Local) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) {
|
|||
case err := <-done:
|
||||
endTime := time.Now()
|
||||
runTime := endTime.Sub(startTime)
|
||||
result := generateResult(
|
||||
result := e.generateResult(
|
||||
err,
|
||||
execCmd.ProcessState,
|
||||
runTime,
|
||||
|
@ -157,7 +157,7 @@ func (e *Local) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) {
|
|||
err := <-done
|
||||
endTime := time.Now()
|
||||
runTime := endTime.Sub(startTime)
|
||||
result := generateResult(
|
||||
result := e.generateResult(
|
||||
err,
|
||||
execCmd.ProcessState,
|
||||
runTime,
|
||||
|
|
|
@ -129,7 +129,7 @@ func convertPathsToRelative(messages *[]ClangMessage, conf Conf) {
|
|||
}
|
||||
}
|
||||
|
||||
func ParseLines(lines []string, conf Conf) []ClangMessage {
|
||||
func parseLines(lines []string, conf Conf) []ClangMessage {
|
||||
messages := make([]ClangMessage, 0)
|
||||
for _, line := range lines {
|
||||
if isIgnored(string(line)) {
|
||||
|
|
|
@ -17,7 +17,7 @@ type JsonMessage struct {
|
|||
Severity string `json:"severity"`
|
||||
}
|
||||
|
||||
func Format(messages []ClangMessage) []JsonMessage {
|
||||
func format(messages []ClangMessage) []JsonMessage {
|
||||
formattedMessages := make([]JsonMessage, len(messages))
|
||||
for i, message := range messages {
|
||||
formattedMessages[i] = formatMessage(message)
|
||||
|
|
|
@ -6,20 +6,20 @@ import (
|
|||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||
)
|
||||
|
||||
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||
func (*ClangTidy) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||
stdout := executorResult.Files[conf.Stdout]
|
||||
// stderr := executorResult.Files[conf.Stderr]
|
||||
lines := strings.SplitAfter(stdout, "\n")
|
||||
messages := ParseLines(lines, conf)
|
||||
formattedMessages := Format(messages)
|
||||
score, comment := GetResult(formattedMessages, conf)
|
||||
messages := parseLines(lines, conf)
|
||||
formattedMessages := format(messages)
|
||||
score, comment := getResult(formattedMessages, conf)
|
||||
return stage.ParserResult{
|
||||
Score: score,
|
||||
Comment: comment,
|
||||
}
|
||||
}
|
||||
|
||||
func (*ClangTidy) Run(results []stage.ExecutorResult, confAny any) (
|
||||
func (p *ClangTidy) Run(results []stage.ExecutorResult, confAny any) (
|
||||
[]stage.ParserResult, bool, error,
|
||||
) {
|
||||
conf, err := stage.DecodeConf[Conf](confAny)
|
||||
|
@ -29,7 +29,7 @@ func (*ClangTidy) Run(results []stage.ExecutorResult, confAny any) (
|
|||
var res []stage.ParserResult
|
||||
forceQuit := false
|
||||
for _, result := range results {
|
||||
parseRes := Parse(result, *conf)
|
||||
parseRes := p.parse(result, *conf)
|
||||
if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score {
|
||||
forceQuit = true
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
|
||||
func getResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
|
||||
score := conf.Score
|
||||
comment := "### Test results summary\n\n"
|
||||
matchCount := make(map[string]int)
|
||||
|
|
|
@ -17,7 +17,7 @@ type Record struct {
|
|||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||
func (*CppCheck) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||
// stdout := executorResult.Files[conf.Stdout]
|
||||
stderr := executorResult.Files[conf.Stderr]
|
||||
records := make([]Record, 0)
|
||||
|
@ -39,7 +39,7 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
|||
}
|
||||
records = append(records, record)
|
||||
}
|
||||
comment, score, err := GetResult(records, conf)
|
||||
comment, score, err := getResult(records, conf)
|
||||
if err != nil {
|
||||
return stage.ParserResult{
|
||||
Score: 0,
|
||||
|
@ -56,7 +56,7 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
|||
}
|
||||
}
|
||||
|
||||
func (*CppCheck) Run(results []stage.ExecutorResult, confAny any) (
|
||||
func (p *CppCheck) Run(results []stage.ExecutorResult, confAny any) (
|
||||
[]stage.ParserResult, bool, error,
|
||||
) {
|
||||
conf, err := stage.DecodeConf[Conf](confAny)
|
||||
|
@ -66,7 +66,7 @@ func (*CppCheck) Run(results []stage.ExecutorResult, confAny any) (
|
|||
var res []stage.ParserResult
|
||||
forceQuit := false
|
||||
for _, result := range results {
|
||||
parseRes := Parse(result, *conf)
|
||||
parseRes := p.parse(result, *conf)
|
||||
if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score {
|
||||
forceQuit = true
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ const (
|
|||
UNKNOWN
|
||||
)
|
||||
|
||||
func GetResult(records []Record, conf Conf) (string, int, error) {
|
||||
func getResult(records []Record, conf Conf) (string, int, error) {
|
||||
score := conf.Score
|
||||
comment := "### Test results summary\n\n"
|
||||
matchCount := make(map[string]int)
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||
)
|
||||
|
||||
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||
func (*Cpplint) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||
stderr := executorResult.Files[conf.Stderr]
|
||||
pattern := `(.+):(\d+): (.+) \[(.+)\] \[(\d)]\n`
|
||||
re := regexp.MustCompile(pattern)
|
||||
|
@ -72,7 +72,7 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
|||
}
|
||||
}
|
||||
|
||||
func (*Cpplint) Run(results []stage.ExecutorResult, confAny any) (
|
||||
func (p *Cpplint) Run(results []stage.ExecutorResult, confAny any) (
|
||||
[]stage.ParserResult, bool, error,
|
||||
) {
|
||||
conf, err := stage.DecodeConf[Conf](confAny)
|
||||
|
@ -82,7 +82,7 @@ func (*Cpplint) Run(results []stage.ExecutorResult, confAny any) (
|
|||
var res []stage.ParserResult
|
||||
forceQuit := false
|
||||
for _, result := range results {
|
||||
parseRes := Parse(result, *conf)
|
||||
parseRes := p.parse(result, *conf)
|
||||
if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score {
|
||||
forceQuit = true
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||
)
|
||||
|
||||
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||
func (*Debug) parse(executorResult stage.ExecutorResult, _ Conf) stage.ParserResult {
|
||||
slog.Debug("debug parser", "executorResult", executorResult)
|
||||
for name, content := range executorResult.Files {
|
||||
slog.Debug("debug parser file", "name", name, "content", content)
|
||||
|
@ -17,7 +17,7 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
|||
}
|
||||
}
|
||||
|
||||
func (*Debug) Run(results []stage.ExecutorResult, confAny any) (
|
||||
func (p *Debug) Run(results []stage.ExecutorResult, confAny any) (
|
||||
[]stage.ParserResult, bool, error,
|
||||
) {
|
||||
conf, err := stage.DecodeConf[Conf](confAny)
|
||||
|
@ -26,7 +26,7 @@ func (*Debug) Run(results []stage.ExecutorResult, confAny any) (
|
|||
}
|
||||
var res []stage.ParserResult
|
||||
for _, result := range results {
|
||||
res = append(res, Parse(result, *conf))
|
||||
res = append(res, p.parse(result, *conf))
|
||||
}
|
||||
return res, false, nil
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/joint-online-judge/JOJ3/pkg/healthcheck"
|
||||
)
|
||||
|
||||
func Parse(executorResult stage.ExecutorResult, conf Conf) (stage.ParserResult, bool) {
|
||||
func (*Healthcheck) parse(executorResult stage.ExecutorResult, conf Conf) (stage.ParserResult, bool) {
|
||||
stdout := executorResult.Files[conf.Stdout]
|
||||
stderr := executorResult.Files[conf.Stderr]
|
||||
slog.Debug("healthcheck files", "stdout", stdout, "stderr", stderr)
|
||||
|
@ -43,7 +43,7 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) (stage.ParserResult,
|
|||
}, forceQuit
|
||||
}
|
||||
|
||||
func (*Healthcheck) Run(results []stage.ExecutorResult, confAny any) (
|
||||
func (p *Healthcheck) Run(results []stage.ExecutorResult, confAny any) (
|
||||
[]stage.ParserResult, bool, error,
|
||||
) {
|
||||
conf, err := stage.DecodeConf[Conf](confAny)
|
||||
|
@ -53,7 +53,7 @@ func (*Healthcheck) Run(results []stage.ExecutorResult, confAny any) (
|
|||
var res []stage.ParserResult
|
||||
forceQuit := false
|
||||
for _, result := range results {
|
||||
parserResult, forceQuitResult := Parse(result, *conf)
|
||||
parserResult, forceQuitResult := p.parse(result, *conf)
|
||||
res = append(res, parserResult)
|
||||
forceQuit = forceQuit || forceQuitResult
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||
)
|
||||
|
||||
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||
func (*Keyword) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||
score := conf.Score
|
||||
comment := ""
|
||||
matchCount := make(map[string]int)
|
||||
|
@ -59,7 +59,7 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
|||
}
|
||||
}
|
||||
|
||||
func (*Keyword) Run(results []stage.ExecutorResult, confAny any) (
|
||||
func (k *Keyword) Run(results []stage.ExecutorResult, confAny any) (
|
||||
[]stage.ParserResult, bool, error,
|
||||
) {
|
||||
conf, err := stage.DecodeConf[Conf](confAny)
|
||||
|
@ -69,7 +69,7 @@ func (*Keyword) Run(results []stage.ExecutorResult, confAny any) (
|
|||
var res []stage.ParserResult
|
||||
forceQuit := false
|
||||
for _, result := range results {
|
||||
parseRes := Parse(result, *conf)
|
||||
parseRes := k.parse(result, *conf)
|
||||
if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score {
|
||||
forceQuit = true
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||
)
|
||||
|
||||
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||
func (*Log) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||
content := executorResult.Files[conf.FileName]
|
||||
var data map[string]any
|
||||
err := json.Unmarshal([]byte(content), &data)
|
||||
|
@ -36,7 +36,7 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
|||
}
|
||||
}
|
||||
|
||||
func (*Log) Run(results []stage.ExecutorResult, confAny any) (
|
||||
func (p *Log) Run(results []stage.ExecutorResult, confAny any) (
|
||||
[]stage.ParserResult, bool, error,
|
||||
) {
|
||||
conf, err := stage.DecodeConf[Conf](confAny)
|
||||
|
@ -45,7 +45,7 @@ func (*Log) Run(results []stage.ExecutorResult, confAny any) (
|
|||
}
|
||||
var res []stage.ParserResult
|
||||
for _, result := range results {
|
||||
res = append(res, Parse(result, *conf))
|
||||
res = append(res, p.parse(result, *conf))
|
||||
}
|
||||
return res, false, nil
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/joint-online-judge/JOJ3/pkg/sample"
|
||||
)
|
||||
|
||||
func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||
func (*Sample) parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
||||
stdout := executorResult.Files[conf.Stdout]
|
||||
// stderr := executorResult.Files[conf.Stderr]
|
||||
var sampleResult sample.Result
|
||||
|
@ -25,7 +25,7 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
|||
}
|
||||
}
|
||||
|
||||
func (*Sample) Run(results []stage.ExecutorResult, confAny any) (
|
||||
func (p *Sample) Run(results []stage.ExecutorResult, confAny any) (
|
||||
[]stage.ParserResult, bool, error,
|
||||
) {
|
||||
conf, err := stage.DecodeConf[Conf](confAny)
|
||||
|
@ -34,7 +34,7 @@ func (*Sample) Run(results []stage.ExecutorResult, confAny any) (
|
|||
}
|
||||
var res []stage.ParserResult
|
||||
for _, result := range results {
|
||||
res = append(res, Parse(result, *conf))
|
||||
res = append(res, p.parse(result, *conf))
|
||||
}
|
||||
return res, false, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user