From 8b2bd31e45670ac249deffab27eadb98bdca4bff Mon Sep 17 00:00:00 2001 From: yingying Date: Thu, 12 Dec 2024 18:17:38 +0800 Subject: [PATCH] chore: fix cr --- server/bot/router.py | 16 ++++++++++------ server/bot/util.ts | 0 server/core/dao/repositoryConfigDAO.py | 3 +-- 3 files changed, 11 insertions(+), 8 deletions(-) delete mode 100644 server/bot/util.ts diff --git a/server/bot/router.py b/server/bot/router.py index 4518f28e..14fa3162 100644 --- a/server/bot/router.py +++ b/server/bot/router.py @@ -29,7 +29,6 @@ def get_bot_list( None, description="Filter bots by personal category" ), name: Optional[str] = Query(None, description="Filter bots by name"), - user_id: Annotated[str | None, Depends(get_user_id)] = None, user: Annotated[User | None, Depends(get_user)] = None, ): try: @@ -38,20 +37,25 @@ def get_bot_list( "id, created_at, updated_at, avatar, description, name, public, starters, uid, repo_name" ) if personal == "true": - if not user_id: + if not user or not user.access_token: return {"data": [], "personal": personal} - + user_id = user.id auth = Auth.Token(token=user.access_token) g = Github(auth=auth) github_user = g.get_user() orgs = github_user.get_orgs() repository_config_dao = RepositoryConfigDAO() - bots = repository_config_dao.query_by_owners( + bots = repository_config_dao.query_bot_id_by_owners( [org.id for org in orgs] + [github_user.id] ) - bot_ids = [bot["robot_id"] for bot in bots] + bot_ids = [bot["robot_id"] for bot in bots if bot["robot_id"]] bot_ids_str = ",".join(map(str, bot_ids)) # 将 bots ID 列表转换为字符串 - or_clause = f"uid.eq.{user_id},id.in.({bot_ids_str})" + + or_clause = ( + f"uid.eq.{user_id},id.in.({bot_ids_str})" + if bot_ids_str + else f"uid.eq.{user_id}" + ) # 添加过滤条件 query = ( diff --git a/server/bot/util.ts b/server/bot/util.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/server/core/dao/repositoryConfigDAO.py b/server/core/dao/repositoryConfigDAO.py index 128a63f4..e1f8f6d1 100644 --- a/server/core/dao/repositoryConfigDAO.py +++ b/server/core/dao/repositoryConfigDAO.py @@ -74,7 +74,7 @@ def query_by_owners(self, orgs: List[str]): try: response = ( self.client.table("github_repo_config") - .select("robot_id") + .select("*") .filter("owner_id", "in", f"({','.join(map(str, orgs))})") .execute() ) @@ -89,7 +89,6 @@ def query_bot_id_by_owners(self, orgs: List[str]): self.client.table("github_repo_config") .select("robot_id") .filter("owner_id", "in", f"({','.join(map(str, orgs))})") - .filter("robot_id", "isnot", None) .execute() ) return response.data