Skip to content

Commit

Permalink
chore: fix cr
Browse files Browse the repository at this point in the history
  • Loading branch information
xingwanying committed Dec 12, 2024
1 parent c40bba1 commit 8b2bd31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
16 changes: 10 additions & 6 deletions server/bot/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 = (
Expand Down
Empty file removed server/bot/util.ts
Empty file.
3 changes: 1 addition & 2 deletions server/core/dao/repositoryConfigDAO.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand All @@ -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
Expand Down

0 comments on commit 8b2bd31

Please sign in to comment.