feat(cmd/joj3/main_test.go,-internal/scoreboard/scoreboard.go,-scripts/submit_scoreboard.sh): removing unused function in scoreboard
This commit is contained in:
		
							parent
							
								
									1d135c7cab
								
							
						
					
					
						commit
						e80f4b55da
					
				|  | @ -71,7 +71,7 @@ func removeStringPrefix(s, prefix string) string { | |||
| 
 | ||||
| func TestMain(t *testing.T) { | ||||
| 	scoreboard := scoreboard.Scoreboard{} | ||||
| 	scoreboard.Init("TestingStudent", "520370000000") | ||||
| 	scoreboard.Init() | ||||
| 	var tests []string | ||||
| 	root := "../../tmp/submodules/JOJ3-examples" | ||||
| 	err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { | ||||
|  | @ -130,7 +130,5 @@ func TestMain(t *testing.T) { | |||
| 	} | ||||
| 	if !t.Failed() { | ||||
| 		scoreboard.SaveFile("../../score.json") | ||||
| 		// defer os.Remove("../../score.json")
 | ||||
| 		// scoreboard.Submit()
 | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -1,12 +1,8 @@ | |||
| package scoreboard | ||||
| 
 | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"log/slog" | ||||
| 	"os" | ||||
| 	"os/exec" | ||||
| 
 | ||||
| 	"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" | ||||
| ) | ||||
|  | @ -21,14 +17,10 @@ type ScoreboardData struct { | |||
| } | ||||
| 
 | ||||
| type Scoreboard struct { | ||||
| 	studentName string | ||||
| 	studentId   string | ||||
| 	scoreboard  ScoreboardData | ||||
| 	scoreboard ScoreboardData | ||||
| } | ||||
| 
 | ||||
| func (b *Scoreboard) Init(studentName string, studentId string) { | ||||
| 	b.studentName = studentName | ||||
| 	b.studentId = studentId | ||||
| func (b *Scoreboard) Init() { | ||||
| 	b.scoreboard.StageRecords = make([]StageRecord, 0) | ||||
| } | ||||
| 
 | ||||
|  | @ -46,54 +38,3 @@ func (b *Scoreboard) SaveFile(filePath string) { | |||
| 	encoder.SetIndent("", "  ") | ||||
| 	_ = encoder.Encode(b.scoreboard) | ||||
| } | ||||
| 
 | ||||
| func (b *Scoreboard) Submit() { | ||||
| 	e := os.Mkdir("repos", 0o777) | ||||
| 	if e != nil { | ||||
| 		slog.Error("Encountered problems createing folder: ", "err", e) | ||||
| 		return | ||||
| 	} | ||||
| 	var teapotCommand string | ||||
| 	origHome := os.Getenv("ORIG_HOME") | ||||
| 	if origHome != "" { | ||||
| 		// For drone server
 | ||||
| 		teapotCommand = fmt.Sprintf("cp %s/.config/ci/teapot.env .env && joint-teapot JOJ3-scoreboard \"../../scoreboard.json\" %s %s \"JOJ3-examples\" \"JOJ3_dev.csv\"", origHome, b.studentName, b.studentId) | ||||
| 	} else { | ||||
| 		// For local developers
 | ||||
| 		jointTeapotRoot := os.Getenv("TEAPOT_ROOT") | ||||
| 		if jointTeapotRoot == "" { | ||||
| 			slog.Error("Unable to find joint-teapot. Have you configured environment variable TEAPOT_ROOT?") | ||||
| 			return | ||||
| 		} | ||||
| 		teapotCommand = fmt.Sprintf("cp %s/.env .env && source %s/env/bin/activate && python3 -m joint_teapot JOJ3-scoreboard \"../../scoreboard.json\" %s %s \"JOJ3-examples\" \"JOJ3_dev.csv\" && deactivate", jointTeapotRoot, jointTeapotRoot, b.studentName, b.studentId) | ||||
| 	} | ||||
| 	defer os.Remove(".env") | ||||
| 	teapotCmd := exec.Command("/bin/bash", "-c", teapotCommand) | ||||
| 	defer os.Remove("joint-teapot.log") | ||||
| 
 | ||||
| 	stderrPipe, err := teapotCmd.StderrPipe() | ||||
| 	if err != nil { | ||||
| 		slog.Error("Error creating stderr pipe when submitting scoreboard: ", "err", err) | ||||
| 		return | ||||
| 	} | ||||
| 	err = teapotCmd.Start() | ||||
| 	if err != nil { | ||||
| 		slog.Error("Error starting command when submitting scoreboard: ", "err", err) | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	var stderr bytes.Buffer | ||||
| 	_, err = stderr.ReadFrom(stderrPipe) | ||||
| 	if err != nil { | ||||
| 		slog.Error("Error reading stderr when submitting scoreboard: ", "err", err) | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	err = teapotCmd.Wait() | ||||
| 	if err != nil { | ||||
| 		slog.Error("Tried to submit scoreboard, but it finished with error: ", "err", err) | ||||
| 		slog.Error("Stderr output:", "stderr", stderr.String()) | ||||
| 		return | ||||
| 	} | ||||
| 	slog.Info("Scoreboard was submitted with following outputs: ", "stderr", stderr.String()) | ||||
| } | ||||
|  |  | |||
|  | @ -19,4 +19,5 @@ echo 'MATTERMOST_ACCESS_TOKEN=""' >> .env | |||
| echo 'MATTERMOST_TEACHING_TEAM=[]' >> .env | ||||
| 
 | ||||
| joint-teapot JOJ3-scoreboard "score.json" $SUBMITTER_NAME "" "JOJ3-examples" "JOJ3_dev.csv" | ||||
| cat joint-teapot.log | ||||
| rm score.json | ||||
| rm .env | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user