From df3069c9b760ecd0fb24036d7b13f791b1ea4e88 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Wed, 21 Aug 2024 21:36:39 +0800 Subject: [PATCH] feat: read repo config --- server/dao/repositoryConfigDAO.py | 18 +++++++++++++++--- server/event_handler/issue.py | 6 +++++- server/models/repository.py | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/server/dao/repositoryConfigDAO.py b/server/dao/repositoryConfigDAO.py index ece2ea02..fff0e68a 100644 --- a/server/dao/repositoryConfigDAO.py +++ b/server/dao/repositoryConfigDAO.py @@ -15,13 +15,25 @@ def __init__(self): def create(self, data: RepositoryConfig): print('supabase github_repo_config creation', data.model_dump()) try: - authorization = self.client.from_("github_repo_config")\ + repo_config = self.client.from_("github_repo_config")\ .insert(data.model_dump())\ .execute() - if authorization: + if repo_config: return True, {"message": "GithubRepoConfig created successfully"} else: return False, {"message": "GithubRepoConfig creation failed"} except Exception as e: print("Error: ", e) - return False, {"message": "GithubRepoConfig creation failed"} \ No newline at end of file + return False, {"message": "GithubRepoConfig creation failed"} + + def get_by_repo_name(self, repo_name: str): + response = self.client.table("github_repo_config")\ + .select('*')\ + .eq("repo_name", repo_name) \ + .execute() + + if not response.data or not response.data[0]: + return None + repo_config = response.data[0] + print(f"repo_config={repo_config}") + return RepositoryConfig(**repo_config) diff --git a/server/event_handler/issue.py b/server/event_handler/issue.py index 3485fde3..f5b59a19 100644 --- a/server/event_handler/issue.py +++ b/server/event_handler/issue.py @@ -2,6 +2,7 @@ from github import Github, Auth from github import GithubException +from dao.repositoryConfigDAO import RepositoryConfigDAO from petercat_utils.data_class import ChatData, Message, TextContentBlock from agent.qa_chat import agent_chat @@ -18,6 +19,7 @@ def __init__(self, payload: Any, auth: Auth.AppAuth, installation_id: int) -> No self.g: Github = Github(auth=auth) async def execute(self): + repository_config = RepositoryConfigDAO() try: print("actions:", self.event["action"]) if self.event["action"] == "opened": @@ -29,7 +31,9 @@ async def execute(self): text_block = TextContentBlock(type="text", text=issue_content) issue_content = issue.body message = Message(role="user", content=[text_block]) - analysis_result = await agent_chat(ChatData(messages=[message]), None) + + repo_config = repository_config.get_by_repo_name(repo_name) + analysis_result = await agent_chat(ChatData(messages=[message], bot_id=repo_config.robot_id), None) issue.create_comment(analysis_result["output"]) return {"success": True} diff --git a/server/models/repository.py b/server/models/repository.py index 83ac0c73..ebfcb793 100644 --- a/server/models/repository.py +++ b/server/models/repository.py @@ -3,6 +3,7 @@ from pydantic import BaseModel class RepositoryConfig(BaseModel): + id: str repo_name: str robot_id: Optional[str] created_at: datetime \ No newline at end of file