chore(parser): make unnecessary methods private
All checks were successful
submodules sync / sync (push) Successful in 43s
build / build (push) Successful in 1m46s
build / trigger-build-image (push) Successful in 9s

This commit is contained in:
张泊明518370910136 2025-02-17 09:22:29 -05:00
parent 1e75ab1c6e
commit b4e706f8e9
GPG Key ID: D47306D7062CDA9D
15 changed files with 38 additions and 38 deletions

View File

@ -34,7 +34,7 @@ func GetCommitMsg() (msg string, err error) {
return return
} }
func ParseConventionalCommit(commit string) (*ConventionalCommit, error) { func parseConventionalCommit(commit string) (*ConventionalCommit, error) {
re := regexp.MustCompile(`(?s)^(\w+)(\(([^)]+)\))?!?: (.+?(\[([^\]]+)\])?)(\n\n(.+?))?(\n\n(.+))?$`) re := regexp.MustCompile(`(?s)^(\w+)(\(([^)]+)\))?!?: (.+?(\[([^\]]+)\])?)(\n\n(.+?))?(\n\n(.+))?$`)
matches := re.FindStringSubmatch(strings.TrimSpace(commit)) matches := re.FindStringSubmatch(strings.TrimSpace(commit))
if matches == nil { if matches == nil {
@ -91,7 +91,7 @@ func parseMsg(confRoot, confName, msg, tag string) (
confPath string, conventionalCommit *ConventionalCommit, err error, confPath string, conventionalCommit *ConventionalCommit, err error,
) { ) {
slog.Info("parse msg", "msg", msg) slog.Info("parse msg", "msg", msg)
conventionalCommit, err = ParseConventionalCommit(msg) conventionalCommit, err = parseConventionalCommit(msg)
if err != nil { if err != nil {
return return
} }

View File

@ -119,7 +119,7 @@ func TestParseConventionalCommit(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got, err := ParseConventionalCommit(tt.commit) got, err := parseConventionalCommit(tt.commit)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("ParseConventionalCommit() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("ParseConventionalCommit() error = %v, wantErr %v", err, tt.wantErr)
return return

View File

@ -15,7 +15,7 @@ import (
"github.com/joint-online-judge/JOJ3/internal/stage" "github.com/joint-online-judge/JOJ3/internal/stage"
) )
func generateResult( func (e *Local) generateResult(
err error, err error,
processState *os.ProcessState, processState *os.ProcessState,
runTime time.Duration, runTime time.Duration,
@ -134,7 +134,7 @@ func (e *Local) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) {
case err := <-done: case err := <-done:
endTime := time.Now() endTime := time.Now()
runTime := endTime.Sub(startTime) runTime := endTime.Sub(startTime)
result := generateResult( result := e.generateResult(
err, err,
execCmd.ProcessState, execCmd.ProcessState,
runTime, runTime,
@ -157,7 +157,7 @@ func (e *Local) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) {
err := <-done err := <-done
endTime := time.Now() endTime := time.Now()
runTime := endTime.Sub(startTime) runTime := endTime.Sub(startTime)
result := generateResult( result := e.generateResult(
err, err,
execCmd.ProcessState, execCmd.ProcessState,
runTime, runTime,

View File

@ -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) messages := make([]ClangMessage, 0)
for _, line := range lines { for _, line := range lines {
if isIgnored(string(line)) { if isIgnored(string(line)) {

View File

@ -17,7 +17,7 @@ type JsonMessage struct {
Severity string `json:"severity"` Severity string `json:"severity"`
} }
func Format(messages []ClangMessage) []JsonMessage { func format(messages []ClangMessage) []JsonMessage {
formattedMessages := make([]JsonMessage, len(messages)) formattedMessages := make([]JsonMessage, len(messages))
for i, message := range messages { for i, message := range messages {
formattedMessages[i] = formatMessage(message) formattedMessages[i] = formatMessage(message)

View File

@ -6,20 +6,20 @@ import (
"github.com/joint-online-judge/JOJ3/internal/stage" "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] stdout := executorResult.Files[conf.Stdout]
// stderr := executorResult.Files[conf.Stderr] // stderr := executorResult.Files[conf.Stderr]
lines := strings.SplitAfter(stdout, "\n") lines := strings.SplitAfter(stdout, "\n")
messages := ParseLines(lines, conf) messages := parseLines(lines, conf)
formattedMessages := Format(messages) formattedMessages := format(messages)
score, comment := GetResult(formattedMessages, conf) score, comment := getResult(formattedMessages, conf)
return stage.ParserResult{ return stage.ParserResult{
Score: score, Score: score,
Comment: comment, Comment: comment,
} }
} }
func (*ClangTidy) Run(results []stage.ExecutorResult, confAny any) ( func (p *ClangTidy) Run(results []stage.ExecutorResult, confAny any) (
[]stage.ParserResult, bool, error, []stage.ParserResult, bool, error,
) { ) {
conf, err := stage.DecodeConf[Conf](confAny) conf, err := stage.DecodeConf[Conf](confAny)
@ -29,7 +29,7 @@ func (*ClangTidy) Run(results []stage.ExecutorResult, confAny any) (
var res []stage.ParserResult var res []stage.ParserResult
forceQuit := false forceQuit := false
for _, result := range results { for _, result := range results {
parseRes := Parse(result, *conf) parseRes := p.parse(result, *conf)
if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score { if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score {
forceQuit = true forceQuit = true
} }

View File

@ -6,7 +6,7 @@ import (
"strings" "strings"
) )
func GetResult(jsonMessages []JsonMessage, conf Conf) (int, string) { func getResult(jsonMessages []JsonMessage, conf Conf) (int, string) {
score := conf.Score score := conf.Score
comment := "### Test results summary\n\n" comment := "### Test results summary\n\n"
matchCount := make(map[string]int) matchCount := make(map[string]int)

View File

@ -17,7 +17,7 @@ type Record struct {
Id string `json:"id"` 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] // stdout := executorResult.Files[conf.Stdout]
stderr := executorResult.Files[conf.Stderr] stderr := executorResult.Files[conf.Stderr]
records := make([]Record, 0) records := make([]Record, 0)
@ -39,7 +39,7 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
} }
records = append(records, record) records = append(records, record)
} }
comment, score, err := GetResult(records, conf) comment, score, err := getResult(records, conf)
if err != nil { if err != nil {
return stage.ParserResult{ return stage.ParserResult{
Score: 0, 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, []stage.ParserResult, bool, error,
) { ) {
conf, err := stage.DecodeConf[Conf](confAny) conf, err := stage.DecodeConf[Conf](confAny)
@ -66,7 +66,7 @@ func (*CppCheck) Run(results []stage.ExecutorResult, confAny any) (
var res []stage.ParserResult var res []stage.ParserResult
forceQuit := false forceQuit := false
for _, result := range results { for _, result := range results {
parseRes := Parse(result, *conf) parseRes := p.parse(result, *conf)
if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score { if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score {
forceQuit = true forceQuit = true
} }

View File

@ -19,7 +19,7 @@ const (
UNKNOWN UNKNOWN
) )
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"
matchCount := make(map[string]int) matchCount := make(map[string]int)

View File

@ -9,7 +9,7 @@ import (
"github.com/joint-online-judge/JOJ3/internal/stage" "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] stderr := executorResult.Files[conf.Stderr]
pattern := `(.+):(\d+): (.+) \[(.+)\] \[(\d)]\n` pattern := `(.+):(\d+): (.+) \[(.+)\] \[(\d)]\n`
re := regexp.MustCompile(pattern) 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, []stage.ParserResult, bool, error,
) { ) {
conf, err := stage.DecodeConf[Conf](confAny) conf, err := stage.DecodeConf[Conf](confAny)
@ -82,7 +82,7 @@ func (*Cpplint) Run(results []stage.ExecutorResult, confAny any) (
var res []stage.ParserResult var res []stage.ParserResult
forceQuit := false forceQuit := false
for _, result := range results { for _, result := range results {
parseRes := Parse(result, *conf) parseRes := p.parse(result, *conf)
if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score { if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score {
forceQuit = true forceQuit = true
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/joint-online-judge/JOJ3/internal/stage" "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) slog.Debug("debug parser", "executorResult", executorResult)
for name, content := range executorResult.Files { for name, content := range executorResult.Files {
slog.Debug("debug parser file", "name", name, "content", content) 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, []stage.ParserResult, bool, error,
) { ) {
conf, err := stage.DecodeConf[Conf](confAny) conf, err := stage.DecodeConf[Conf](confAny)
@ -26,7 +26,7 @@ func (*Debug) Run(results []stage.ExecutorResult, confAny any) (
} }
var res []stage.ParserResult var res []stage.ParserResult
for _, result := range results { for _, result := range results {
res = append(res, Parse(result, *conf)) res = append(res, p.parse(result, *conf))
} }
return res, false, nil return res, false, nil
} }

View File

@ -10,7 +10,7 @@ import (
"github.com/joint-online-judge/JOJ3/pkg/healthcheck" "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] stdout := executorResult.Files[conf.Stdout]
stderr := executorResult.Files[conf.Stderr] stderr := executorResult.Files[conf.Stderr]
slog.Debug("healthcheck files", "stdout", stdout, "stderr", stderr) slog.Debug("healthcheck files", "stdout", stdout, "stderr", stderr)
@ -43,7 +43,7 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) (stage.ParserResult,
}, forceQuit }, forceQuit
} }
func (*Healthcheck) Run(results []stage.ExecutorResult, confAny any) ( func (p *Healthcheck) Run(results []stage.ExecutorResult, confAny any) (
[]stage.ParserResult, bool, error, []stage.ParserResult, bool, error,
) { ) {
conf, err := stage.DecodeConf[Conf](confAny) conf, err := stage.DecodeConf[Conf](confAny)
@ -53,7 +53,7 @@ func (*Healthcheck) Run(results []stage.ExecutorResult, confAny any) (
var res []stage.ParserResult var res []stage.ParserResult
forceQuit := false forceQuit := false
for _, result := range results { for _, result := range results {
parserResult, forceQuitResult := Parse(result, *conf) parserResult, forceQuitResult := p.parse(result, *conf)
res = append(res, parserResult) res = append(res, parserResult)
forceQuit = forceQuit || forceQuitResult forceQuit = forceQuit || forceQuitResult
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/joint-online-judge/JOJ3/internal/stage" "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 score := conf.Score
comment := "" comment := ""
matchCount := make(map[string]int) 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, []stage.ParserResult, bool, error,
) { ) {
conf, err := stage.DecodeConf[Conf](confAny) conf, err := stage.DecodeConf[Conf](confAny)
@ -69,7 +69,7 @@ func (*Keyword) Run(results []stage.ExecutorResult, confAny any) (
var res []stage.ParserResult var res []stage.ParserResult
forceQuit := false forceQuit := false
for _, result := range results { for _, result := range results {
parseRes := Parse(result, *conf) parseRes := k.parse(result, *conf)
if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score { if conf.ForceQuitOnDeduct && parseRes.Score < conf.Score {
forceQuit = true forceQuit = true
} }

View File

@ -9,7 +9,7 @@ import (
"github.com/joint-online-judge/JOJ3/internal/stage" "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] content := executorResult.Files[conf.FileName]
var data map[string]any var data map[string]any
err := json.Unmarshal([]byte(content), &data) 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, []stage.ParserResult, bool, error,
) { ) {
conf, err := stage.DecodeConf[Conf](confAny) conf, err := stage.DecodeConf[Conf](confAny)
@ -45,7 +45,7 @@ func (*Log) Run(results []stage.ExecutorResult, confAny any) (
} }
var res []stage.ParserResult var res []stage.ParserResult
for _, result := range results { for _, result := range results {
res = append(res, Parse(result, *conf)) res = append(res, p.parse(result, *conf))
} }
return res, false, nil return res, false, nil
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/joint-online-judge/JOJ3/pkg/sample" "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] stdout := executorResult.Files[conf.Stdout]
// stderr := executorResult.Files[conf.Stderr] // stderr := executorResult.Files[conf.Stderr]
var sampleResult sample.Result 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, []stage.ParserResult, bool, error,
) { ) {
conf, err := stage.DecodeConf[Conf](confAny) conf, err := stage.DecodeConf[Conf](confAny)
@ -34,7 +34,7 @@ func (*Sample) Run(results []stage.ExecutorResult, confAny any) (
} }
var res []stage.ParserResult var res []stage.ParserResult
for _, result := range results { for _, result := range results {
res = append(res, Parse(result, *conf)) res = append(res, p.parse(result, *conf))
} }
return res, false, nil return res, false, nil
} }