XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Check for existing comments

270bc8a4
Heiner Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +8 -7
Modified etc/tool/copilot.py +8 -7
@@ -30,7 +30,6 @@ def get_pr_details(github: Github) -> PullRequest:
30 30 Returns:
31 31 PullRequest: An object representing the pull request.
32 32 """
33 './pr_number'
34 33 with open('./pr_number', 'r') as file:
35 34 pr_number = int(file.read())
36 35 if not pr_number:
@@ -132,8 +131,8 @@ def analyze_code(pull: PullRequest, diff: str)-> list[dict]:
132 131 if match:
133 132 offset_line = int(match.group(1))
134 133 elif current_file_path:
135 if line.startswith('\\') or line.startswith('diff') and changed_lines:
136 prompt = create_prompt(changed_lines, pull, current_file_path)
134 if (line.startswith('\\') or line.startswith('diff')) and changed_lines:
135 prompt = create_analyze_prompt(changed_lines, pull, current_file_path)
137 136 response = get_ai_response(prompt)
138 137 for review in response.get('reviews', []):
139 138 review['path'] = current_file_path
@@ -146,7 +145,7 @@ def analyze_code(pull: PullRequest, diff: str)-> list[dict]:
146 145
147 146 return comments
148 147
149 def create_prompt(changed_lines: list[str], pull: PullRequest, file_path: str):
148 def create_analyze_prompt(changed_lines: list[str], pull: PullRequest, file_path: str):
150 149 """
151 150 Creates a prompt for the g4f model.
152 151
@@ -194,10 +193,9 @@ def create_review_prompt(pull: PullRequest, diff: str):
194 193 str: The generated prompt for review.
195 194 """
196 195 return f"""Your task is to review a pull request. Instructions:
197 - Write in name of you "g4f-copilot".
196 - Write in name of g4f copilot. Don't use placeholder.
198 197 - Write the review in GitHub Markdown format.
199 198 - Thank the author for contributing to the project.
200 - Point out that you might leave a few comments on the files.
201 199
202 200 Pull request author: {pull.user.name}
203 201 Pull request title: {pull.title}
@@ -219,6 +217,9 @@ def main():
219 217 if not pull:
220 218 print(f"No PR number found")
221 219 exit()
220 if pull.get_reviews().totalCount > 0 or pull.get_comments().totalCount > 0:
221 print(f"Has already a review")
222 exit()
222 223 diff = get_diff(pull.diff_url)
223 224 except Exception as e:
224 225 print(f"Error get details: {e.__class__.__name__}: {e}")
@@ -235,7 +236,7 @@ def main():
235 236 exit(1)
236 237 print("Comments:", comments)
237 238 try:
238 if not comments:
239 if comments:
239 240 pull.create_review(body=review, comments=comments)
240 241 else:
241 242 pull.create_comment(body=review)