Add official USTC school sync#1
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new school command tree that authenticates against official USTC systems (CAS + jw / catalog / Blackboard / yjs1) and exposes semesters, curriculum, exams, scores, and homework, plus a one-way sync of school lessons/homework into Life@USTC. Adds an undergraduate/graduate program selector with credential resolution from flags, env vars, or .env, and persists a default program list via a new config set-school-programs command.
Changes:
- New
internal/schoolpackage: HTTP/CAS client, undergraduate (jw/catalog/Blackboard) and graduate (yjs1) data sources, TOTP, credentials, models, and debug helpers, with unit tests. - New
internal/cmd/schoolpackage wiringsemesters,curriculum,exam,score,homework, andsynccommands (with--graduate/--undergraduate/--all-programs/--dry-run/--debug), plus root and config-command integration. - Config schema gains a
schoolProgramsfield, and README documents the new commands and credential env vars.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents the new school subcommands, credential env vars, and program default config. |
| internal/school/program.go | Adds Program type with undergraduate/graduate constants. |
| internal/school/models.go | Shared data models and sort helpers for semesters/curriculum/exam/score/homework. |
| internal/school/client.go | Main client: undergraduate jw/catalog/Blackboard fetchers, HTML/JSON parsers, dispatcher across programs. |
| internal/school/client_test.go | Tests for Blackboard ID filtering, batching, URL building, grade-status and exam parsing. |
| internal/school/graduate.go | Graduate yjs1 fetchers for semesters, schedule, exams, scores, and homework. |
| internal/school/graduate_test.go | Unit tests for graduate row mappers and homework status logic. |
| internal/school/browser.go | CAS login flow, cookie jar, password encryption, multi-target authentication. |
| internal/school/credentials.go | Credential resolution from flags / env / .env, plus program detection. |
| internal/school/credentials_test.go | Tests for credential resolution, OTP, and semester picking. |
| internal/school/totp.go | TOTP/otpauth code computation supporting SHA1/256/512. |
| internal/school/debug.go | Package-level debug logger and step timer helpers. |
| internal/school/score_parser_test.go | Test for the rendered jw score-report HTML parser. |
| internal/cmd/school/school.go | All school subcommands and the Life@USTC sync orchestration. |
| internal/cmd/school/school_test.go | Tests for life-semester resolution, completion mapping, Blackboard code parsing, and homework matching. |
| internal/cmd/root/root.go | Registers the new school command in the browse group. |
| internal/cmd/root/root_test.go | Adds school to expected commands and group assertions. |
| internal/cmd/configcmd/config.go | Adds set-school-programs / get-school-programs subcommands and parser. |
| internal/cmd/configcmd/config_test.go | Tests for the new program parser. |
| internal/config/config.go | Adds SchoolPrograms field with getter/setter. |
| go.mod / go.sum | Adds goquery, godotenv, and transitive deps. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+334
to
+337
| for _, data := range response.Datas { | ||
| return data.Rows, nil | ||
| } | ||
| return nil, nil |
Comment on lines
+1278
to
+1283
| func schoolHomeworkCompleted(item ustcschool.HomeworkItem) bool { | ||
| completed, _ := schoolHomeworkCompletion(item) | ||
| return completed | ||
| } | ||
|
|
||
| func schoolHomeworkCompletion(item ustcschool.HomeworkItem) (bool, bool) { |
Comment on lines
+107
to
+109
| func openAuthenticatedClient(ctx context.Context, creds Credentials, target loginTarget) (*http.Client, error) { | ||
| return openAuthenticatedClientForTargets(ctx, creds, []loginTarget{target}) | ||
| } |
Comment on lines
+31
to
+33
| func debugStepf(format string, args ...any) func() { | ||
| return debugStep(fmt.Sprintf(format, args...)) | ||
| } |
| } | ||
|
|
||
| func fetchJSON[T any](ctx context.Context, client *http.Client, rawURL string, query url.Values, out *T) error { | ||
| if query != nil && len(query) > 0 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Testing
Notes