Skip to content

Commit

Permalink
feat: read repo config
Browse files Browse the repository at this point in the history
  • Loading branch information
RaoHai committed Aug 21, 2024
1 parent 4e8eaf5 commit df3069c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
18 changes: 15 additions & 3 deletions server/dao/repositoryConfigDAO.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
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)
6 changes: 5 additions & 1 deletion server/event_handler/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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":
Expand All @@ -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}
Expand Down
1 change: 1 addition & 0 deletions server/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pydantic import BaseModel

class RepositoryConfig(BaseModel):
id: str
repo_name: str
robot_id: Optional[str]
created_at: datetime

0 comments on commit df3069c

Please sign in to comment.