mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-10 15:28:14 -05:00
[Resolver][Bug]: Fix success list to str representation bug (#5351)
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
This commit is contained in:
@@ -187,6 +187,13 @@ def make_commit(repo_dir: str, issue: GithubIssue, issue_type: str) -> None:
|
||||
|
||||
|
||||
def branch_exists(base_url: str, branch_name: str, headers: dict) -> bool:
|
||||
"""Check if a branch exists in the GitHub repository.
|
||||
|
||||
Args:
|
||||
base_url: The base URL of the GitHub repository API
|
||||
branch_name: The name of the branch to check
|
||||
headers: The HTTP headers to use for authentication
|
||||
"""
|
||||
print(f'Checking if branch {branch_name} exists...')
|
||||
response = requests.get(f'{base_url}/branches/{branch_name}', headers=headers)
|
||||
exists = response.status_code == 200
|
||||
@@ -334,6 +341,33 @@ def reply_to_comment(github_token: str, comment_id: str, reply: str):
|
||||
response.raise_for_status()
|
||||
|
||||
|
||||
def send_comment_msg(base_url: str, issue_number: int, github_token: str, msg: str):
|
||||
"""Send a comment message to a GitHub issue or pull request.
|
||||
|
||||
Args:
|
||||
base_url: The base URL of the GitHub repository API
|
||||
issue_number: The issue or pull request number
|
||||
github_token: The GitHub token to use for authentication
|
||||
msg: The message content to post as a comment
|
||||
"""
|
||||
# Set up headers for GitHub API
|
||||
headers = {
|
||||
'Authorization': f'token {github_token}',
|
||||
'Accept': 'application/vnd.github.v3+json',
|
||||
}
|
||||
|
||||
# Post a comment on the PR
|
||||
comment_url = f'{base_url}/issues/{issue_number}/comments'
|
||||
comment_data = {'body': msg}
|
||||
comment_response = requests.post(comment_url, headers=headers, json=comment_data)
|
||||
if comment_response.status_code != 201:
|
||||
print(
|
||||
f'Failed to post comment: {comment_response.status_code} {comment_response.text}'
|
||||
)
|
||||
else:
|
||||
print(f'Comment added to the PR: {msg}')
|
||||
|
||||
|
||||
def update_existing_pull_request(
|
||||
github_issue: GithubIssue,
|
||||
github_token: str,
|
||||
@@ -354,11 +388,7 @@ def update_existing_pull_request(
|
||||
comment_message: The main message to post as a comment on the PR.
|
||||
additional_message: The additional messages to post as a comment on the PR in json list format.
|
||||
"""
|
||||
# Set up headers and base URL for GitHub API
|
||||
headers = {
|
||||
'Authorization': f'token {github_token}',
|
||||
'Accept': 'application/vnd.github.v3+json',
|
||||
}
|
||||
# Set up base URL for GitHub API
|
||||
base_url = f'https://api.github.com/repos/{github_issue.owner}/{github_issue.repo}'
|
||||
branch_name = github_issue.head_branch
|
||||
|
||||
@@ -412,24 +442,18 @@ def update_existing_pull_request(
|
||||
|
||||
# Post a comment on the PR
|
||||
if comment_message:
|
||||
comment_url = f'{base_url}/issues/{github_issue.number}/comments'
|
||||
comment_data = {'body': comment_message}
|
||||
comment_response = requests.post(
|
||||
comment_url, headers=headers, json=comment_data
|
||||
)
|
||||
if comment_response.status_code != 201:
|
||||
print(
|
||||
f'Failed to post comment: {comment_response.status_code} {comment_response.text}'
|
||||
)
|
||||
else:
|
||||
print(f'Comment added to the PR: {comment_message}')
|
||||
send_comment_msg(base_url, github_issue.number, github_token, comment_message)
|
||||
|
||||
# Reply to each unresolved comment thread
|
||||
if additional_message and github_issue.thread_ids:
|
||||
explanations = json.loads(additional_message)
|
||||
for count, reply_comment in enumerate(explanations):
|
||||
comment_id = github_issue.thread_ids[count]
|
||||
reply_to_comment(github_token, comment_id, reply_comment)
|
||||
try:
|
||||
explanations = json.loads(additional_message)
|
||||
for count, reply_comment in enumerate(explanations):
|
||||
comment_id = github_issue.thread_ids[count]
|
||||
reply_to_comment(github_token, comment_id, reply_comment)
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
msg = f'Error occured when replying to threads; success explanations {additional_message}'
|
||||
send_comment_msg(base_url, github_issue.number, github_token, msg)
|
||||
|
||||
return pr_url
|
||||
|
||||
|
||||
Reference in New Issue
Block a user