Fix issue #5086: [Bug]: resolver: Error finding issue with empty description (#5357)

Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
This commit is contained in:
OpenHands
2024-12-02 09:23:16 -05:00
committed by GitHub
parent cd22817004
commit 809b58de89
2 changed files with 49 additions and 2 deletions

View File

@@ -167,12 +167,17 @@ class IssueHandler(IssueHandlerInterface):
converted_issues = []
for issue in all_issues:
if any([issue.get(key) is None for key in ['number', 'title', 'body']]):
# Check for required fields (number and title)
if any([issue.get(key) is None for key in ['number', 'title']]):
logger.warning(
f'Skipping issue {issue} as it is missing number, title, or body.'
f'Skipping issue {issue} as it is missing number or title.'
)
continue
# Handle empty body by using empty string
if issue.get('body') is None:
issue['body'] = ''
# Get issue thread comments
thread_comments = self._get_issue_comments(
issue['number'], comment_id=comment_id

View File

@@ -46,6 +46,48 @@ def test_get_converted_issues_initializes_review_comments():
assert issues[0].repo == 'test-repo'
def test_get_converted_issues_handles_empty_body():
# Mock the necessary dependencies
with patch('requests.get') as mock_get:
# Mock the response for issues
mock_issues_response = MagicMock()
mock_issues_response.json.return_value = [
{'number': 1, 'title': 'Test Issue', 'body': None}
]
# Mock the response for comments
mock_comments_response = MagicMock()
mock_comments_response.json.return_value = []
# Set up the mock to return different responses
mock_get.side_effect = [
mock_issues_response,
mock_comments_response,
mock_comments_response,
]
# Create an instance of IssueHandler
llm_config = LLMConfig(model='test', api_key='test')
handler = IssueHandler('test-owner', 'test-repo', 'test-token', llm_config)
# Get converted issues
issues = handler.get_converted_issues(issue_numbers=[1])
# Verify that we got exactly one issue
assert len(issues) == 1
# Verify that body is empty string when None
assert issues[0].body == ''
# Verify other fields are set correctly
assert issues[0].number == 1
assert issues[0].title == 'Test Issue'
assert issues[0].owner == 'test-owner'
assert issues[0].repo == 'test-repo'
# Verify that review_comments is initialized as None
assert issues[0].review_comments is None
def test_pr_handler_get_converted_issues_with_comments():
# Mock the necessary dependencies
with patch('requests.get') as mock_get: