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

feat: add skip key words for the pull request handler and issue handler #601

Merged
merged 2 commits into from
Dec 20, 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
11 changes: 7 additions & 4 deletions server/agent/prompts/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- create_review_comment: Used to leave a review comment on specific files.

# Task
You have two Pull Requst review task with basic infomation:
You have two Pull Request review task with basic information:
```
repo_name: {repo_name}
pull_number: {pull_number}
Expand Down Expand Up @@ -55,6 +55,10 @@
- The + sign means that code has been added.
- The - sign means that code has been removed.

# Skip Task Whitelist
**SKIP_KEYWORDS**: A list of keywords. If any of these keywords are present in the PR title or description, the corresponding task will be skipped.
- Examples: "skip", "ignore", "wip", "merge", "[skip ci]"

# Constraints
- Strictly avoid commenting on minor style inconsistencies, formatting issues, or changes that do not impact functionality.
- Do not review files outside of the modified changeset (i.e., if a file has no diffs, it should not be reviewed).
Expand Down Expand Up @@ -123,7 +127,6 @@ def get_role_prompt(repo_name: str, pull_number: int, title: str, description: s
description=description,
)


def generate_pr_review_comment_prompt(pr_number: str, pr_content: str):
return PR_REVIEW_COMMENT_PROMPT.format(
pr_number=pr_number, pr_content=pr_content
)
return PR_REVIEW_COMMENT_PROMPT.format(pr_number=pr_number, pr_content=pr_content)
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 @@
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}

Check warning on line 99 in server/event_handler/discussion.py

View check run for this annotation

Codecov / codecov/patch

server/event_handler/discussion.py#L96-L99

Added lines #L96 - L99 were not covered by tests
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
9 changes: 7 additions & 2 deletions server/event_handler/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from agent.bot.get_bot import get_bot_by_id
from core.models.bot import BotModel

from utils.fuzzy_match import contains_keyword_fuzzy
from utils.path_to_hunk import convert_patch_to_hunk
from utils.random_str import random_str
from agent.prompts.pull_request import (
Expand All @@ -22,6 +23,7 @@
from core.dao.repositoryConfigDAO import RepositoryConfigDAO
from petercat_utils.data_class import ChatData, Message, TextContentBlock


Check warning on line 26 in server/event_handler/pull_request.py

View check run for this annotation

Codecov / codecov/patch

server/event_handler/pull_request.py#L26

Added line #L26 was not covered by tests
def file_match(filename: str, patterns: List[str]):
return any(fnmatch.fnmatch(filename, pattern) for pattern in patterns)

Expand Down Expand Up @@ -132,6 +134,7 @@
print(f"处理 GitHub 请求时出错:{e}")
return {"success": False, "error": str(e)}


Check warning on line 137 in server/event_handler/pull_request.py

View check run for this annotation

Codecov / codecov/patch

server/event_handler/pull_request.py#L137

Added line #L137 was not covered by tests
class PullRequestReviewCommentEventHandler(PullRequestEventHandler):
def not_mentioned_me(self):
return "@petercat-assistant" not in self.event["comment"]["body"]
Expand All @@ -145,7 +148,7 @@
if self.not_mentioned_me():
return {"success": True}

comment_id = self.event["comment"]['id']
comment_id = self.event["comment"]["id"]
pr, diff, repo = self.get_pull_request()
file_diff = self.get_file_diff(diff)

Expand Down Expand Up @@ -188,7 +191,9 @@
bot,
)

pr.create_review_comment_reply(comment_id, analysis_result["output"])
pr.create_review_comment_reply(
comment_id, analysis_result["output"]

Check warning on line 195 in server/event_handler/pull_request.py

View check run for this annotation

Codecov / codecov/patch

server/event_handler/pull_request.py#L194-L195

Added lines #L194 - L195 were not covered by tests
)

except GithubException as e:
print(f"处理 GitHub 请求时出错:{e}")
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):
xingwanying marked this conversation as resolved.
Show resolved Hide resolved
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
Loading