Skip to content

Commit

Permalink
Fix issue #5086: [Bug]: resolver: Error finding issue with empty desc…
Browse files Browse the repository at this point in the history
…ription (#5357)

Co-authored-by: Engel Nyst <[email protected]>
  • Loading branch information
openhands-agent and enyst authored Dec 2, 2024
1 parent cd22817 commit 809b58d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
9 changes: 7 additions & 2 deletions openhands/resolver/issue_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/resolver/test_issue_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 809b58d

Please sign in to comment.