Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: solve the issue where the configuration information of robots from other organizations cannot be found #588

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions server/bot/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,25 @@ def get_bot_detail(
@router.get("/config")
def get_bot_config(
id: Optional[str] = Query(None, description="Filter bots by personal category"),
user_id: Annotated[str | None, Depends(get_user_id)] = None,
user: Annotated[User | None, Depends(get_user)] = None,
):
if not user or not user.access_token or not id:
return {"data": []}
try:
auth = Auth.Token(token=user.access_token)
github_user = Github(auth=auth).get_user()
orgs_ids = [org.id for org in github_user.get_orgs()]
bot_ids = []

repository_config_dao = RepositoryConfigDAO()
bots = repository_config_dao.query_bot_id_by_owners(orgs_ids + [github_user.id])

bot_ids = [bot["robot_id"] for bot in bots if bot["robot_id"]]
xingwanying marked this conversation as resolved.
Show resolved Hide resolved
bot_ids.append(id)

supabase = get_client()
data = (
supabase.table("bots").select("*").eq("id", id).eq("uid", user_id).execute()
supabase.table("bots").select("*").eq("id", id).in_("id", bot_ids).execute()
)
return {"data": data.data, "status": 200}
except Exception as e:
Expand Down
12 changes: 6 additions & 6 deletions server/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from fastapi.testclient import TestClient

from env import ENVIRONMENT, WEB_URL, API_URL
from petercat_utils import get_env_variable
from main import app

Check failure on line 4 in server/tests/test_main.py

View workflow job for this annotation

GitHub Actions / build

Ruff (F401)

tests/test_main.py:4:28: F401 `petercat_utils.get_env_variable` imported but unused

client = TestClient(app)


def test_health_checker():
response = client.get("/api/health_checker")
assert response.status_code == 200
assert response.json() == {
'ENVIRONMENT': ENVIRONMENT,
'API_URL': API_URL,
'CALLBACK_URL': f'{API_URL}/api/auth/callback',
'WEB_URL': WEB_URL,
}
"ENVIRONMENT": ENVIRONMENT,
"API_URL": API_URL,
"CALLBACK_URL": f"{API_URL}/api/auth/callback",
"WEB_URL": WEB_URL,
}
Loading