From 1c90f55013d85f6f45692b8f0142323a1b6ef049 Mon Sep 17 00:00:00 2001 From: BoYanZh Date: Wed, 19 Feb 2025 22:55:46 -0500 Subject: [PATCH] feat: get jaccount from sjtu email --- joint_teapot/workers/gitea.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/joint_teapot/workers/gitea.py b/joint_teapot/workers/gitea.py index 33b763e..e115326 100644 --- a/joint_teapot/workers/gitea.py +++ b/joint_teapot/workers/gitea.py @@ -79,9 +79,13 @@ class Gitea: @lru_cache() def _get_username_by_canvas_student(self, student: User) -> str: - if student.integration_id is None: - raise Exception(f"{student} id not found in Gitea") - return student.integration_id + if ( + student.email is not None + and student.email.count("@") == 1 + and student.email.endswith("@sjtu.edu.cn") + ): + return student.email.split("@")[0] + raise Exception(f"Can not get username of {student}, an SJTU email is expected") def add_canvas_students_to_teams( self, students: PaginatedList, team_names: List[str]