Skip to content

Commit

Permalink
feat: add skip key words for the pull request handler
Browse files Browse the repository at this point in the history
  • Loading branch information
xingwanying committed Dec 20, 2024
1 parent 5e02b36 commit 29f992a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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)
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 @@ async def execute(self):
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 @@ async def execute(self):
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 @@ async def execute(self):
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

0 comments on commit 29f992a

Please sign in to comment.