Skip to content

Commit

Permalink
feat: add skip key words for the issue handler
Browse files Browse the repository at this point in the history
  • Loading branch information
xingwanying committed Dec 20, 2024
1 parent f5443ba commit 5e02b36
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
8 changes: 7 additions & 1 deletion server/event_handler/discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@


from agent.qa_chat import agent_chat
from utils.fuzzy_match import contains_keyword_fuzzy

BOT_NAME = "petercat-assistant"
SKIP_KEYWORDS = ["RFC", "skip"]


class DiscussionEventHandler:
Expand Down Expand Up @@ -91,7 +93,11 @@ async def handle_discussion_event(self, action: str):
owner = self.event["organization"]["login"]
repo_name = self.event["repository"]["full_name"]
discussion = self.event["discussion"]
discussion_content = f"{discussion['title']}: {discussion['body']}"
title = discussion["title"]
is_skip = contains_keyword_fuzzy(title, SKIP_KEYWORDS)
if is_skip:
return {"success": True}
discussion_content = f"{title}: {discussion['body']}"
text_block = TextContentBlock(type="text", text=discussion_content)
discussion_number = discussion["number"]
message = Message(role="user", content=[text_block])
Expand Down
7 changes: 6 additions & 1 deletion server/event_handler/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
generate_issue_comment_prompt,
generate_issue_prompt,
)

from core.dao.repositoryConfigDAO import RepositoryConfigDAO
from petercat_utils.data_class import ChatData, Message, TextContentBlock

from agent.qa_chat import agent_chat
from utils.fuzzy_match import contains_keyword_fuzzy

SKIP_KEYWORDS = ["RFC", "skip"]


class IssueEventHandler:
Expand Down Expand Up @@ -40,6 +42,9 @@ async def execute(self):
return {"success": True}
if action in ["opened", "reopened"]:
issue, repo = self.get_issue()
is_skip = contains_keyword_fuzzy(issue.title, SKIP_KEYWORDS)
if is_skip:
return {"success": True}

prompt = generate_issue_prompt(
repo_name=repo.full_name,
Expand Down
15 changes: 15 additions & 0 deletions server/utils/fuzzy_match.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import difflib


def contains_keyword_fuzzy(text, keywords, cutoff=0.8):
text_lower = text.lower()
for keyword in keywords:
keyword_lower = keyword.lower()
len_keyword = len(keyword_lower)

for i in range(len(text_lower) - len_keyword + 1):
substring = text_lower[i : i + len_keyword]
matcher = difflib.SequenceMatcher(None, keyword_lower, substring)
if matcher.ratio() >= cutoff:
return True
return False

0 comments on commit 5e02b36

Please sign in to comment.