Skip to content

Commit

Permalink
fix: add the function to check if the pr summary is correct and fix it
Browse files Browse the repository at this point in the history
  • Loading branch information
xingwanying committed Dec 31, 2024
1 parent c5669c7 commit 42ae9c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
16 changes: 9 additions & 7 deletions server/agent/prompts/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@
## Task 1: Summarize the Pull Request
Using `create_pr_summary` tool to create PR summary.
Provider your response in markdown with the following content. follow the user's language.
Provider your response in markdown with the following content.
- **Walkthrough**: A high-level summary of the overall change instead of specific files within 80 words.
- **Changes**: A markdown table of files and their summaries. Group files with similar changes together into a single row to save space.
### Additional Instructions:
- Carefully check the markdown format. If there are any errors, fix them before providing the final result.
- Respond in the language of the PR title and content (e.g., if the title/content is in Chinese, reply in Chinese; if it's in English, reply in English).
- At the end of the conversation, be sure to include the following wording and adhere to the language used in previous conversations:
<details>
<summary>🪧 Tips</summary>
For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me.
</details>
<details> <summary>🪧 Tips</summary> For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me. </details>
## Task 2: Code Review
Expand All @@ -46,11 +48,11 @@
- Only the code diff is available for you to review, not the entire codebase.
- Make comments only on code introducing clear and critical functional or security errors.
- Do not comment on documentation, style, accuracy of text, or minor refactoring changes.
- Provide absolutely no feedback if no critical errors are found.
- If necessary, provide code examples only for addressing critical errors.
- Adhere to language-specific coding conventions used in the PR.
- If there are critical errors to comment on, use the `create_review_comment` tool to create review comments.
- Skip the task if no errors are found.
- Avoid providing suggestions related to code optimization or best practices (e.g., "ensure" or "make sure") unless they address critical errors.
- Skip the task entirely if no critical errors are found in the code diff.
- Upon completing the task, output strictly "All task finished", with no additional commentary.
Expand Down
11 changes: 10 additions & 1 deletion server/agent/tools/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional
from github import Github, Auth, ContentFile
import json
import re

from langchain.tools import tool
from agent.tools.helper import need_github_login
Expand Down Expand Up @@ -48,6 +49,10 @@ def get_file_content(repo_name: str, path: str, ref: Optional[str] = None):
print(traceback.format_exception(e))
return json.dumps([])

def fix_markdown_format(markdown_str: str) -> str:
fixed_str = re.sub(r"\\n", "\n", markdown_str)
return fixed_str

@tool
def create_pr_summary(repo_name: str, pull_number: int, summary: str):
"""
Expand All @@ -62,7 +67,11 @@ def create_pr_summary(repo_name: str, pull_number: int, summary: str):
g = Github(auth=token)
repo = g.get_repo(repo_name)
pull_request = repo.get_pull(pull_number)
pull_request.create_issue_comment(summary)

# check if the summary is correct and fix it
format_summary = fix_markdown_format(summary)
print(f"summary:{format_summary}")
pull_request.create_issue_comment(format_summary)
return json.dumps([])

@tool
Expand Down
1 change: 0 additions & 1 deletion server/core/models/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class BotModel(BaseModel):
temperature: Optional[float] = 0.2
n: Optional[int] = 1
top_p: Optional[float] = None



class RepoBindBotConfigVO(BaseModel):
Expand Down

0 comments on commit 42ae9c3

Please sign in to comment.