π OpenHands: AI-Driven Development
Handle deleted GitHub issues (410 error) gracefully (#13217)
Rohit Malhotrabf769d17447a
diff --git a/enterprise/integrations/github/github_v1_callback_processor.py b/enterprise/integrations/github/github_v1_callback_processor.pyindex 541cb27377..42e68027ca 100644--- a/enterprise/integrations/github/github_v1_callback_processor.py+++ b/enterprise/integrations/github/github_v1_callback_processor.py@@ -3,7 +3,7 @@ from typing import Anyfrom uuid import UUIDimport httpx-from github import Auth, Github, GithubIntegration+from github import Auth, Github, GithubException, GithubIntegrationfrom integrations.utils import get_summary_instructionfrom integrations.v1_utils import handle_callback_errorfrom pydantic import Field@@ -132,19 +132,30 @@ class GithubV1CallbackProcessor(EventCallbackProcessor):full_repo_name = self.github_view_data['full_repo_name']issue_number = self.github_view_data['issue_number']- if self.inline_pr_comment:+ try:+ if self.inline_pr_comment:+ with Github(auth=Auth.Token(installation_token)) as github_client:+ repo = github_client.get_repo(full_repo_name)+ pr = repo.get_pull(issue_number)+ pr.create_review_comment_reply(+ comment_id=self.github_view_data.get('comment_id', ''),+ body=summary,+ )+ return+with Github(auth=Auth.Token(installation_token)) as github_client:repo = github_client.get_repo(full_repo_name)- pr = repo.get_pull(issue_number)- pr.create_review_comment_reply(- comment_id=self.github_view_data.get('comment_id', ''), body=summary+ issue = repo.get_issue(number=issue_number)+ issue.create_comment(summary)+ except GithubException as e:+ if e.status == 410:+ _logger.info(+ '[GitHub V1] Issue/PR %s#%s was deleted, skipping summary post',+ full_repo_name,+ issue_number,)- return-- with Github(auth=Auth.Token(installation_token)) as github_client:- repo = github_client.get_repo(full_repo_name)- issue = repo.get_issue(number=issue_number)- issue.create_comment(summary)+ else:+ raise# -------------------------------------------------------------------------# Agent / sandbox helpersdiff --git a/enterprise/tests/unit/integrations/github/test_github_v1_callback_processor.py b/enterprise/tests/unit/integrations/github/test_github_v1_callback_processor.pyindex 36ada82fe8..4e8e500318 100644--- a/enterprise/tests/unit/integrations/github/test_github_v1_callback_processor.py+++ b/enterprise/tests/unit/integrations/github/test_github_v1_callback_processor.py@@ -15,6 +15,7 @@ from uuid import uuid4import httpximport pytest+from github import GithubExceptionfrom integrations.github.github_v1_callback_processor import (GithubV1CallbackProcessor,)@@ -734,6 +735,33 @@ class TestGithubV1CallbackProcessor:with pytest.raises(RuntimeError, match='Missing GitHub credentials'):await github_callback_processor._post_summary_to_github('Test summary')+ @patch('integrations.github.github_v1_callback_processor.Auth')+ @patch('integrations.github.github_v1_callback_processor.Github')+ async def test_post_summary_to_github_deleted_issue_does_not_raise(+ self, mock_github, mock_auth, github_callback_processor+ ):+ """Test that 410 errors (deleted issues) are handled gracefully without raising."""+ mock_github_client = MagicMock()+ mock_repo = MagicMock()+ mock_repo.get_issue.side_effect = GithubException(+ status=410,+ data={'message': 'This issue was deleted'},+ headers={},+ )+ mock_github_client.get_repo.return_value = mock_repo+ mock_github.return_value.__enter__.return_value = mock_github_client++ mock_token_auth = MagicMock()+ mock_auth.Token.return_value = mock_token_auth++ with patch.object(+ github_callback_processor,+ '_get_installation_access_token',+ return_value='test_token',+ ):+ # Should not raise - 410 errors are handled gracefully+ await github_callback_processor._post_summary_to_github('Test summary')+@patch('integrations.github.github_v1_callback_processor.GITHUB_APP_CLIENT_ID','test_client_id',