Repository: All-Hands-AI/OpenHands
File: enterprise/integrations/gitlab/gitlab_manager.py (Python)

Code before:
        has_write_access = await self._user_has_write_access_to_repo(
            project_id=str(project_id), user_id=user_id
        )

        logger.info(
            f'[GitLab]: {username} access in {selected_project}: {has_write_access}'
        )
        # Check if the user has write access to the repository
        return has_write_access

    async def send_message(self, message: Message, gitlab_view: ResolverViewInterface):
        """
        Send a message to GitLab based on the view type.

        Args:
            message: The message to send
            gitlab_view: The GitLab view object containing issue/PR/comment info
        """
        keycloak_user_id = gitlab_view.user_info.keycloak_user_id
        gitlab_service: SaaSGitLabService = GitLabServiceImpl(
            external_auth_id=keycloak_user_id
        )

        outgoing_message = message.message

        if isinstance(gitlab_view, GitlabInlineMRComment) or isinstance(
            gitlab_view, GitlabMRComment
        ):
            await gitlab_service.reply_to_mr(
                gitlab_view.project_id,
                gitlab_view.issue_number,
                gitlab_view.discussion_id,
                message.message,
            )

        elif isinstance(gitlab_view, GitlabIssueComment):
            await gitlab_service.reply_to_issue(
                gitlab_view.project_id,
                gitlab_view.issue_number,
                gitlab_view.discussion_id,
                outgoing_message,
            )
        elif isinstance(gitlab_view, GitlabIssue):
            await gitlab_service.reply_to_issue(
                gitlab_view.project_id,
                gitlab_view.issue_number,
                None,  # no discussion id, issue is tagged
                outgoing_message,
            )
        else:
            logger.warning(

Review comment (bug):
In other places we raise when it's the wrong class, which is arguably better, but still just one runtime error vs another because it would soon try to call a non-existent method.

Code after:
        )

        has_write_access = await self._user_has_write_access_to_repo(
            project_id=str(project_id), user_id=user_id
        )

        logger.info(
            f'[GitLab]: {username} access in {selected_project}: {has_write_access}'
        )
        # Check if the user has write access to the repository
        return has_write_access

    async def send_message(self, message: Message, gitlab_view: ResolverViewInterface):
        """
        Send a message to GitLab based on the view type.

        Args:
            message: The message to send
            gitlab_view: The GitLab view object containing issue/PR/comment info
        """
        keycloak_user_id = gitlab_view.user_info.keycloak_user_id

        # Importing here prevents circular import
        from integrations.gitlab.gitlab_service import SaaSGitLabService

        gitlab_service: SaaSGitLabService = GitLabServiceImpl(
            external_auth_id=keycloak_user_id
        )

        outgoing_message = message.message

        if isinstance(gitlab_view, GitlabInlineMRComment) or isinstance(
            gitlab_view, GitlabMRComment
        ):
            await gitlab_service.reply_to_mr(
                gitlab_view.project_id,
                gitlab_view.issue_number,
                gitlab_view.discussion_id,
                message.message,
            )

        elif isinstance(gitlab_view, GitlabIssueComment):
            await gitlab_service.reply_to_issue(
                gitlab_view.project_id,
                gitlab_view.issue_number,
                gitlab_view.discussion_id,
                outgoing_message,
            )
        elif isinstance(gitlab_view, GitlabIssue):
            await gitlab_service.reply_to_issue(
                gitlab_view.project_id,