Skip to content

Commit 86ff5c8

Browse files
committed
Swap to only doing a comment not suggestion
1 parent fde9f28 commit 86ff5c8

File tree

2 files changed

+67
-34
lines changed

2 files changed

+67
-34
lines changed

benchmarks/lowq2_reconstruction/PRfunctions.py

Lines changed: 62 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ def find_line_number_of_change(original_content, old_value):
172172
# =============================================================================
173173

174174
def create_pr_suggestion(repo_owner, repo_name, pr_number, calibration_file, xml_file, line_number, suggested_line, head_sha, github_token):
175-
"""Create a PR review with code suggestion or update existing one"""
176-
print(f"Creating/updating PR review with suggestion for #{pr_number}...")
175+
"""Create a PR comment with proposed changes"""
176+
print(f"Creating PR comment with calibration update for #{pr_number}...")
177177

178178
headers = {
179179
'Accept': 'application/vnd.github+json',
@@ -182,27 +182,42 @@ def create_pr_suggestion(repo_owner, repo_name, pr_number, calibration_file, xml
182182

183183
bot_comment_base = f"🤖 **Automated Calibration `{calibration_file}` Update**"
184184

185-
# Check for existing review comments from bot
186-
existing_comment_id = find_existing_bot_comment(repo_owner, repo_name, pr_number, bot_comment_base, xml_file, line_number, github_token)
185+
# Check for existing comments from bot
186+
existing_comment_id = find_existing_bot_comment_general(repo_owner, repo_name, pr_number, bot_comment_base, github_token)
187187

188188
# Generate timestamp for the comment
189189
timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
190190

191-
suggestion_body = f"""{bot_comment_base}{' (Updated)' if existing_comment_id else ''}
191+
# Get current line content for context
192+
content = get_file_content(repo_owner, repo_name, xml_file, head_sha, github_token)
193+
lines = content.split('\n') if content else []
194+
current_line = lines[line_number - 1].strip() if line_number <= len(lines) else "Line not found"
195+
196+
comment_body = f"""{bot_comment_base}{' (Updated)' if existing_comment_id else ''}
192197
193198
A new calibration has been generated and is ready for use.
194199
200+
**File:** `{xml_file}`
201+
**Line:** {line_number}
195202
**Last updated:** {timestamp}
196203
197-
```suggestion
198-
{suggested_line}
199-
```"""
204+
**Current line:**
205+
```xml
206+
{current_line}
207+
```
208+
209+
**Proposed change:**
210+
```xml
211+
{suggested_line.strip()}
212+
```
213+
214+
Please update the calibration URL in `{xml_file}` at line {line_number}."""
200215

201216
if existing_comment_id:
202217
# Update existing comment
203218
print(f"Updating existing comment {existing_comment_id}...")
204-
update_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/pulls/comments/{existing_comment_id}"
205-
update_data = {'body': suggestion_body}
219+
update_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues/comments/{existing_comment_id}"
220+
update_data = {'body': comment_body}
206221
response = requests.patch(update_url, headers=headers, json=update_data)
207222

208223
if response.status_code == 200:
@@ -213,30 +228,19 @@ def create_pr_suggestion(repo_owner, repo_name, pr_number, calibration_file, xml
213228
print(f" Response: {response.text}")
214229
return None
215230
else:
216-
# Create new review comment
217-
print("Creating new review comment...")
218-
review_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/pulls/{pr_number}/reviews"
231+
# Create new regular PR comment
232+
print("Creating new PR comment...")
233+
comment_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues/{pr_number}/comments"
219234

220-
review_data = {
221-
'body': f'🤖 Automated review with updated calibration URLs `{calibration_file}` for PR #{pr_number}',
222-
'event': 'COMMENT',
223-
'commit_id': head_sha,
224-
'comments': [
225-
{
226-
'path': xml_file,
227-
'line': line_number,
228-
'body': suggestion_body
229-
}
230-
]
231-
}
235+
comment_data = {'body': comment_body}
232236

233-
response = requests.post(review_url, headers=headers, json=review_data)
237+
response = requests.post(comment_url, headers=headers, json=comment_data)
234238

235-
if response.status_code == 200:
236-
print("✅ New PR review with suggestion created successfully")
239+
if response.status_code == 201:
240+
print("✅ New PR comment created successfully")
237241
return response.json()
238242
else:
239-
print(f"❌ Failed to create PR review: {response.status_code}")
243+
print(f"❌ Failed to create PR comment: {response.status_code}")
240244
print(f" Response: {response.text}")
241245
return None
242246

@@ -269,5 +273,34 @@ def find_existing_bot_comment(repo_owner, repo_name, pr_number, bot_comment_base
269273
print(f"✅ Found existing bot comment: {comment['id']}")
270274
return comment['id']
271275

276+
print("No existing bot comment found")
277+
return None
278+
279+
def find_existing_bot_comment_general(repo_owner, repo_name, pr_number, bot_comment_base, github_token):
280+
"""Find existing bot comment (general PR comment, not line-specific)"""
281+
print(f"Checking for existing bot comments in PR #{pr_number}...")
282+
283+
headers = {
284+
'Accept': 'application/vnd.github+json',
285+
'Authorization': f'token {github_token}'
286+
}
287+
288+
# Get all general comments for the PR
289+
comments_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues/{pr_number}/comments"
290+
response = requests.get(comments_url, headers=headers)
291+
292+
if response.status_code != 200:
293+
print(f"❌ Failed to get PR comments: {response.status_code}")
294+
return None
295+
296+
comments = response.json()
297+
298+
# Look for existing bot comment
299+
for comment in comments:
300+
# Check if it's from the bot (contains the bot identifier)
301+
if bot_comment_base in comment.get('body', ''):
302+
print(f"✅ Found existing bot comment: {comment['id']}")
303+
return comment['id']
304+
272305
print("No existing bot comment found")
273306
return None

benchmarks/lowq2_reconstruction/makePRSuggestion.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env python3
22
"""
3-
Script to create GitHub PR suggestions for ONNX model updates
3+
Script to create GitHub PR comments for ONNX model updates
44
"""
55
import argparse
66
import sys
77
from PRfunctions import *
88

99
# Parse arguments
10-
parser = argparse.ArgumentParser(description='Update the calibration link for a PR')
10+
parser = argparse.ArgumentParser(description='Create a PR comment with calibration update suggestions')
1111
parser.add_argument('--pr', type=str, required=True, help='Pull request number')
1212
parser.add_argument('--newURL', type=str, required=True, help='URL of the new updated calibration')
1313
parser.add_argument('--githubToken', type=str, required=True, help='GitHub token for authentication')
@@ -60,13 +60,13 @@
6060
print(f"✅ Found URL to update in {xml_file} at line {line_number}")
6161
print(f" Suggested change: {suggested_line.strip()}")
6262

63-
# Create the PR review with suggestion
63+
# Create the PR comment with proposed changes
6464
response = create_pr_suggestion(repo_owner, repo_name, pr_number, calibration_file, xml_file, line_number, suggested_line, pr_info['head']['sha'], github_token)
6565

6666
if response:
67-
print("🎉 PR suggestion completed successfully!")
67+
print("🎉 PR comment created successfully!")
6868
else:
69-
print("❌ Failed to create PR suggestion")
69+
print("❌ Failed to create PR comment")
7070
sys.exit(1)
7171
else:
7272
print(f"❌ Failed to find URL to update in {xml_file}")

0 commit comments

Comments
 (0)