Skip to content

Commit

Permalink
fix: support set settings
Browse files Browse the repository at this point in the history
BoYanZh committed Sep 14, 2024

Verified

This commit was signed with the committer’s verified signature.
BoYanZh BoYanZh
1 parent 6303d31 commit cdc86c5
Showing 5 changed files with 38 additions and 19 deletions.
12 changes: 8 additions & 4 deletions joint_teapot/workers/canvas.py
Original file line number Diff line number Diff line change
@@ -15,12 +15,16 @@
class Canvas:
def __init__(
self,
domain_name: str = settings.canvas_domain_name,
suffix: str = settings.canvas_suffix,
access_token: str = settings.canvas_access_token,
course_id: int = settings.canvas_course_id,
domain_name: str = "",
suffix: str = "",
access_token: str = "", # nosec
course_id: int = 0,
grade_filename: str = "GRADE.txt",
):
domain_name = domain_name or settings.canvas_domain_name
suffix = suffix or settings.canvas_suffix
access_token = access_token or settings.canvas_access_token
course_id = course_id or settings.canvas_course_id
self.canvas = PyCanvas(f"https://{domain_name}{suffix}", access_token)
self.course = self.canvas.get_course(course_id)
logger.info(f"Canvas course loaded. {self.course}")
14 changes: 9 additions & 5 deletions joint_teapot/workers/git.py
Original file line number Diff line number Diff line change
@@ -18,16 +18,20 @@
class Git:
def __init__(
self,
git_host: str = settings.git_host,
org_name: str = settings.gitea_org_name,
repos_dir: str = settings.repos_dir,
git_host: str = "",
org_name: str = "",
repos_dir: str = "",
):
git_host = git_host or settings.git_host
org_name = org_name or settings.gitea_org_name
repos_dir = repos_dir or settings.repos_dir
self.git_host = git_host
self.org_name = org_name
if not os.path.isdir(repos_dir):
raise Exception(f"{repos_dir} does not exist! Create it first.")
self.repos_dir = repos_dir
if not os.path.isdir(self.repos_dir):
raise Exception(f"{self.repos_dir} does not exist! Create it first.")
logger.debug("Git initialized")
logger.info(f"repos dir: {self.repos_dir}")

def clone_repo(
self, repo_name: str, branch: str = "master", auto_retry: bool = True
16 changes: 11 additions & 5 deletions joint_teapot/workers/gitea.py
Original file line number Diff line number Diff line change
@@ -40,11 +40,15 @@ def list_all(method: Callable[..., Iterable[T]], *args: Any, **kwargs: Any) -> L
class Gitea:
def __init__(
self,
access_token: str = settings.gitea_access_token,
org_name: str = settings.gitea_org_name,
domain_name: str = settings.gitea_domain_name,
suffix: str = settings.gitea_suffix,
access_token: str = "", # nosec
org_name: str = "",
domain_name: str = "",
suffix: str = "",
):
access_token = access_token or settings.gitea_access_token
org_name = org_name or settings.gitea_org_name
domain_name = domain_name or settings.gitea_domain_name
suffix = suffix or settings.gitea_suffix
self.org_name = org_name
configuration = focs_gitea.Configuration()
configuration.api_key["access_token"] = access_token
@@ -64,7 +68,9 @@ def __init__(

@lru_cache()
def _get_team_id_by_name(self, name: str) -> int:
res = self.organization_api.team_search(self.org_name, q=str(name), limit=1).to_dict()
res = self.organization_api.team_search(
self.org_name, q=str(name), limit=1
).to_dict()
if len(res["data"] or []) == 0:
raise Exception(
f"{name} not found by name in Gitea. Possible reason: you did not join this team."
3 changes: 2 additions & 1 deletion joint_teapot/workers/joj.py
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@


class JOJ:
def __init__(self, sid: str = settings.joj_sid):
def __init__(self, sid: str = ""):
sid = sid or settings.joj_sid
init()
self.submitter = JOJSubmitter(sid, logger)

12 changes: 8 additions & 4 deletions joint_teapot/workers/mattermost.py
Original file line number Diff line number Diff line change
@@ -11,11 +11,15 @@
class Mattermost:
def __init__(
self,
access_token: str = settings.mattermost_access_token,
team_name: str = settings.mattermost_team,
domain_name: str = settings.mattermost_domain_name,
suffix: str = settings.mattermost_suffix,
access_token: str = "", # nosec
team_name: str = "",
domain_name: str = "",
suffix: str = "",
):
access_token = access_token or settings.mattermost_access_token
team_name = team_name or settings.mattermost_team
domain_name = domain_name or settings.mattermost_domain_name
suffix = suffix or settings.mattermost_suffix
self.url = domain_name
self.url_suffix = suffix
self.endpoint = Driver(

0 comments on commit cdc86c5

Please sign in to comment.