diff --git a/openhands/resolver/issue_definitions.py b/openhands/resolver/issue_definitions.py index c4ef33fb351e..66e3036ffa62 100644 --- a/openhands/resolver/issue_definitions.py +++ b/openhands/resolver/issue_definitions.py @@ -167,12 +167,17 @@ def get_converted_issues( 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 diff --git a/tests/unit/resolver/test_issue_handler.py b/tests/unit/resolver/test_issue_handler.py index 7eb20a585e5b..56f012fd77c3 100644 --- a/tests/unit/resolver/test_issue_handler.py +++ b/tests/unit/resolver/test_issue_handler.py @@ -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: