Skip to content

Add official USTC school sync#1

Merged
tiankaima merged 6 commits into
mainfrom
feature/school-official-sync
Jun 1, 2026
Merged

Add official USTC school sync#1
tiankaima merged 6 commits into
mainfrom
feature/school-official-sync

Conversation

@tiankaima

Copy link
Copy Markdown
Member

Summary

  • add official USTC school clients for undergraduate JW/Blackboard and graduate yjs1 data
  • add school CLI commands for semesters, curriculum, exams, scores, homework, and sync
  • add Life@USTC section/homework sync with dry-run, debug timing, program defaults, and explicit undergraduate/graduate selectors

Testing

  • go test ./...

Notes

  • school credentials are read from PASSPORT_UNDERGRADUATE_USERNAME, PASSPORT_GRADUATE_USERNAME, PASSPORT_PASSWORD, and PASSPORT_TOTP
  • sync is one-way to Life@USTC and never writes back to official USTC platforms

Copilot AI review requested due to automatic review settings June 1, 2026 03:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/school package: HTTP/CAS client, undergraduate (jw/catalog/Blackboard) and graduate (yjs1) data sources, TOTP, credentials, models, and debug helpers, with unit tests.
  • New internal/cmd/school package wiring semesters, curriculum, exam, score, homework, and sync commands (with --graduate/--undergraduate/--all-programs/--dry-run/--debug), plus root and config-command integration.
  • Config schema gains a schoolPrograms field, 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 thread internal/school/browser.go Outdated
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 thread internal/school/debug.go Outdated
Comment on lines +31 to +33
func debugStepf(format string, args ...any) func() {
return debugStep(fmt.Sprintf(format, args...))
}
Comment thread internal/school/client.go Outdated
}

func fetchJSON[T any](ctx context.Context, client *http.Client, rawURL string, query url.Values, out *T) error {
if query != nil && len(query) > 0 {
@tiankaima tiankaima merged commit 67b8721 into main Jun 1, 2026
2 checks passed
@tiankaima tiankaima deleted the feature/school-official-sync branch June 1, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants