Fix mypy type errors in enterprise GitLab integration (#13205)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Rohit Malhotra
2026-03-04 11:13:16 -05:00
committed by GitHub
parent b86b2f16af
commit b8db9ecd53
4 changed files with 19 additions and 19 deletions

View File

@@ -107,19 +107,15 @@ class GitlabV1CallbackProcessor(EventCallbackProcessor):
# Import here to avoid circular imports # Import here to avoid circular imports
from integrations.gitlab.gitlab_service import SaaSGitLabService from integrations.gitlab.gitlab_service import SaaSGitLabService
from openhands.integrations.gitlab.gitlab_service import GitLabServiceImpl
keycloak_user_id = self.gitlab_view_data.get('keycloak_user_id') keycloak_user_id = self.gitlab_view_data.get('keycloak_user_id')
if not keycloak_user_id: if not keycloak_user_id:
raise RuntimeError('Missing keycloak user ID for GitLab') raise RuntimeError('Missing keycloak user ID for GitLab')
gitlab_service: SaaSGitLabService = GitLabServiceImpl( gitlab_service = SaaSGitLabService(external_auth_id=keycloak_user_id)
external_auth_id=keycloak_user_id
)
project_id = self.gitlab_view_data['project_id'] project_id = self.gitlab_view_data['project_id']
issue_number = self.gitlab_view_data['issue_number'] issue_number = self.gitlab_view_data['issue_number']
discussion_id = self.gitlab_view_data.get('discussion_id') discussion_id = self.gitlab_view_data['discussion_id']
is_mr = self.gitlab_view_data.get('is_mr', False) is_mr = self.gitlab_view_data.get('is_mr', False)
if is_mr: if is_mr:

View File

@@ -461,7 +461,11 @@ class GitlabFactory:
) )
# Check v1_enabled at construction time - this is the source of truth # Check v1_enabled at construction time - this is the source of truth
v1_enabled = await is_v1_enabled_for_gitlab_resolver(keycloak_user_id) v1_enabled = (
await is_v1_enabled_for_gitlab_resolver(keycloak_user_id)
if keycloak_user_id
else False
)
logger.info( logger.info(
f'[GitLab V1]: User flag found for {keycloak_user_id} is {v1_enabled}' f'[GitLab V1]: User flag found for {keycloak_user_id} is {v1_enabled}'
) )

View File

@@ -69,13 +69,13 @@ async def verify_gitlab_signature(
raise HTTPException(status_code=403, detail='Required payload headers missing!') raise HTTPException(status_code=403, detail='Required payload headers missing!')
if IS_LOCAL_DEPLOYMENT: if IS_LOCAL_DEPLOYMENT:
webhook_secret = 'localdeploymentwebhooktesttoken' webhook_secret: str | None = 'localdeploymentwebhooktesttoken'
else: else:
webhook_secret = await webhook_store.get_webhook_secret( webhook_secret = await webhook_store.get_webhook_secret(
webhook_uuid=webhook_uuid, user_id=user_id webhook_uuid=webhook_uuid, user_id=user_id
) )
if header_webhook_secret != webhook_secret: if not webhook_secret or header_webhook_secret != webhook_secret:
raise HTTPException(status_code=403, detail="Request signatures didn't match!") raise HTTPException(status_code=403, detail="Request signatures didn't match!")

View File

@@ -199,10 +199,10 @@ class TestGitlabV1CallbackProcessor:
@patch('openhands.app_server.config.get_sandbox_service') @patch('openhands.app_server.config.get_sandbox_service')
@patch('openhands.app_server.config.get_httpx_client') @patch('openhands.app_server.config.get_httpx_client')
@patch('integrations.gitlab.gitlab_v1_callback_processor.get_summary_instruction') @patch('integrations.gitlab.gitlab_v1_callback_processor.get_summary_instruction')
@patch('openhands.integrations.gitlab.gitlab_service.GitLabServiceImpl') @patch('integrations.gitlab.gitlab_service.SaaSGitLabService')
async def test_successful_callback_execution_issue( async def test_successful_callback_execution_issue(
self, self,
mock_gitlab_service_impl, mock_saas_gitlab_service_cls,
mock_get_summary_instruction, mock_get_summary_instruction,
mock_get_httpx_client, mock_get_httpx_client,
mock_get_sandbox_service, mock_get_sandbox_service,
@@ -228,7 +228,7 @@ class TestGitlabV1CallbackProcessor:
# GitLab service mock # GitLab service mock
mock_gitlab_service = AsyncMock() mock_gitlab_service = AsyncMock()
mock_gitlab_service_impl.return_value = mock_gitlab_service mock_saas_gitlab_service_cls.return_value = mock_gitlab_service
result = await gitlab_callback_processor( result = await gitlab_callback_processor(
conversation_id=conversation_id, conversation_id=conversation_id,
@@ -245,7 +245,7 @@ class TestGitlabV1CallbackProcessor:
assert gitlab_callback_processor.should_request_summary is False assert gitlab_callback_processor.should_request_summary is False
# Verify GitLab service was called correctly for issue # Verify GitLab service was called correctly for issue
mock_gitlab_service_impl.assert_called_once_with( mock_saas_gitlab_service_cls.assert_called_once_with(
external_auth_id='test_keycloak_user' external_auth_id='test_keycloak_user'
) )
mock_gitlab_service.reply_to_issue.assert_called_once_with( mock_gitlab_service.reply_to_issue.assert_called_once_with(
@@ -265,10 +265,10 @@ class TestGitlabV1CallbackProcessor:
@patch('openhands.app_server.config.get_sandbox_service') @patch('openhands.app_server.config.get_sandbox_service')
@patch('openhands.app_server.config.get_httpx_client') @patch('openhands.app_server.config.get_httpx_client')
@patch('integrations.gitlab.gitlab_v1_callback_processor.get_summary_instruction') @patch('integrations.gitlab.gitlab_v1_callback_processor.get_summary_instruction')
@patch('openhands.integrations.gitlab.gitlab_service.GitLabServiceImpl') @patch('integrations.gitlab.gitlab_service.SaaSGitLabService')
async def test_successful_callback_execution_mr( async def test_successful_callback_execution_mr(
self, self,
mock_gitlab_service_impl, mock_saas_gitlab_service_cls,
mock_get_summary_instruction, mock_get_summary_instruction,
mock_get_httpx_client, mock_get_httpx_client,
mock_get_sandbox_service, mock_get_sandbox_service,
@@ -293,7 +293,7 @@ class TestGitlabV1CallbackProcessor:
# GitLab service mock # GitLab service mock
mock_gitlab_service = AsyncMock() mock_gitlab_service = AsyncMock()
mock_gitlab_service_impl.return_value = mock_gitlab_service mock_saas_gitlab_service_cls.return_value = mock_gitlab_service
result = await gitlab_callback_processor_mr( result = await gitlab_callback_processor_mr(
conversation_id=conversation_id, conversation_id=conversation_id,
@@ -326,10 +326,10 @@ class TestGitlabV1CallbackProcessor:
@patch('openhands.app_server.config.get_sandbox_service') @patch('openhands.app_server.config.get_sandbox_service')
@patch('openhands.app_server.config.get_httpx_client') @patch('openhands.app_server.config.get_httpx_client')
@patch('integrations.gitlab.gitlab_v1_callback_processor.get_summary_instruction') @patch('integrations.gitlab.gitlab_v1_callback_processor.get_summary_instruction')
@patch('openhands.integrations.gitlab.gitlab_service.GitLabServiceImpl') @patch('integrations.gitlab.gitlab_service.SaaSGitLabService')
async def test_exception_handling_posts_error_to_gitlab( async def test_exception_handling_posts_error_to_gitlab(
self, self,
mock_gitlab_service_impl, mock_saas_gitlab_service_cls,
mock_get_summary_instruction, mock_get_summary_instruction,
mock_get_httpx_client, mock_get_httpx_client,
mock_get_sandbox_service, mock_get_sandbox_service,
@@ -355,7 +355,7 @@ class TestGitlabV1CallbackProcessor:
# GitLab service mock # GitLab service mock
mock_gitlab_service = AsyncMock() mock_gitlab_service = AsyncMock()
mock_gitlab_service_impl.return_value = mock_gitlab_service mock_saas_gitlab_service_cls.return_value = mock_gitlab_service
result = await gitlab_callback_processor( result = await gitlab_callback_processor(
conversation_id=conversation_id, conversation_id=conversation_id,