summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-01-21 19:44:17 +0100
committerGitHub <noreply@github.com>2024-01-21 19:44:17 +0100
commitd01f3f6b610ec54f6c63e228fd20447828fdcea3 (patch)
tree08d4d5c0a08bcce5d933c300d3083979c9168125 /etc
parentMerge pull request #1494 from hlohaus/neww (diff)
parentCheck for existing comments (diff)
downloadgpt4free-d01f3f6b610ec54f6c63e228fd20447828fdcea3.tar
gpt4free-d01f3f6b610ec54f6c63e228fd20447828fdcea3.tar.gz
gpt4free-d01f3f6b610ec54f6c63e228fd20447828fdcea3.tar.bz2
gpt4free-d01f3f6b610ec54f6c63e228fd20447828fdcea3.tar.lz
gpt4free-d01f3f6b610ec54f6c63e228fd20447828fdcea3.tar.xz
gpt4free-d01f3f6b610ec54f6c63e228fd20447828fdcea3.tar.zst
gpt4free-d01f3f6b610ec54f6c63e228fd20447828fdcea3.zip
Diffstat (limited to 'etc')
-rw-r--r--etc/tool/copilot.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/etc/tool/copilot.py b/etc/tool/copilot.py
index 5e24e12d..6ee1fb0d 100644
--- a/etc/tool/copilot.py
+++ b/etc/tool/copilot.py
@@ -30,7 +30,6 @@ def get_pr_details(github: Github) -> PullRequest:
Returns:
PullRequest: An object representing the pull request.
"""
- './pr_number'
with open('./pr_number', 'r') as file:
pr_number = int(file.read())
if not pr_number:
@@ -132,8 +131,8 @@ def analyze_code(pull: PullRequest, diff: str)-> list[dict]:
if match:
offset_line = int(match.group(1))
elif current_file_path:
- if line.startswith('\\') or line.startswith('diff') and changed_lines:
- prompt = create_prompt(changed_lines, pull, current_file_path)
+ if (line.startswith('\\') or line.startswith('diff')) and changed_lines:
+ prompt = create_analyze_prompt(changed_lines, pull, current_file_path)
response = get_ai_response(prompt)
for review in response.get('reviews', []):
review['path'] = current_file_path
@@ -146,7 +145,7 @@ def analyze_code(pull: PullRequest, diff: str)-> list[dict]:
return comments
-def create_prompt(changed_lines: list[str], pull: PullRequest, file_path: str):
+def create_analyze_prompt(changed_lines: list[str], pull: PullRequest, file_path: str):
"""
Creates a prompt for the g4f model.
@@ -194,10 +193,9 @@ def create_review_prompt(pull: PullRequest, diff: str):
str: The generated prompt for review.
"""
return f"""Your task is to review a pull request. Instructions:
-- Write in name of you "g4f-copilot".
+- Write in name of g4f copilot. Don't use placeholder.
- Write the review in GitHub Markdown format.
- Thank the author for contributing to the project.
-- Point out that you might leave a few comments on the files.
Pull request author: {pull.user.name}
Pull request title: {pull.title}
@@ -219,6 +217,9 @@ def main():
if not pull:
print(f"No PR number found")
exit()
+ if pull.get_reviews().totalCount > 0 or pull.get_comments().totalCount > 0:
+ print(f"Has already a review")
+ exit()
diff = get_diff(pull.diff_url)
except Exception as e:
print(f"Error get details: {e.__class__.__name__}: {e}")
@@ -235,7 +236,7 @@ def main():
exit(1)
print("Comments:", comments)
try:
- if not comments:
+ if comments:
pull.create_review(body=review, comments=comments)
else:
pull.create_comment(body=review)