Repository: getsentry/sentry

Issue:
Fix typing for `sentry.api.endpoints.organization_derive_code_mappings`
Many files related to post-process are skipping type checks.

* Remove the file from [sentry/pyproject.toml](https://github.com/getsentry/sentry/blob/b7810a9dca4b57afd2858903a6a9ec7ab50cdead/pyproject.toml)
* Run `mypy sentry.api.endpoints.organization_derive_code_mappings` and fix the typing errors

From https://github.com/getsentry/sentry/issues/55193


Discussion:

Resolving patch:
diff --git a/src/sentry/api/endpoints/organization_derive_code_mappings.py b/src/sentry/api/endpoints/organization_derive_code_mappings.py
--- a/src/sentry/api/endpoints/organization_derive_code_mappings.py
+++ b/src/sentry/api/endpoints/organization_derive_code_mappings.py
@@ -48,17 +48,20 @@ def get(self, request: Request, organization: Organization) -> Response:
         installation, _ = get_installation(organization)
         if not installation:
             return self.respond(
-                "Could not find this integration installed on your organization",
+                {"text": "Could not find this integration installed on your organization"},
                 status=status.HTTP_404_NOT_FOUND,
             )
 
-        trees = installation.get_trees_for_org()
+        # This method is specific to the GithubIntegration
+        trees = installation.get_trees_for_org()  # type: ignore
         trees_helper = CodeMappingTreesHelper(trees)
-        frame_filename = FrameFilename(stacktrace_filename)
-        possible_code_mappings: List[Dict[str, str]] = trees_helper.list_file_matches(
-            frame_filename
-        )
-        resp_status = status.HTTP_200_OK if possible_code_mappings else status.HTTP_204_NO_CONTENT
+        possible_code_mappings: List[Dict[str, str]] = []
+        resp_status: int = status.HTTP_204_NO_CONTENT
+        if stacktrace_filename:
+            frame_filename = FrameFilename(stacktrace_filename)
+            possible_code_mappings = trees_helper.list_file_matches(frame_filename)
+            if possible_code_mappings:
+                resp_status = status.HTTP_200_OK
         return Response(serialize(possible_code_mappings), status=resp_status)
 
     def post(self, request: Request, organization: Organization) -> Response:
@@ -78,23 +81,27 @@ def post(self, request: Request, organization: Organization) -> Response:
             return Response(status=status.HTTP_403_FORBIDDEN)
 
         installation, organization_integration = get_installation(organization)
-        if not installation:
+        if not installation or not organization_integration:
             return self.respond(
-                "Could not find this integration installed on your organization",
+                {"text": "Could not find this integration installed on your organization"},
                 status=status.HTTP_404_NOT_FOUND,
             )
 
         try:
             project = Project.objects.get(id=request.data.get("projectId"))
         except Project.DoesNotExist:
-            return self.respond("Could not find project", status=status.HTTP_404_NOT_FOUND)
+            return self.respond(
+                {"text": "Could not find project"}, status=status.HTTP_404_NOT_FOUND
+            )
 
         repo_name = request.data.get("repoName")
         stack_root = request.data.get("stackRoot")
         source_root = request.data.get("sourceRoot")
         branch = request.data.get("defaultBranch")
         if not repo_name or not stack_root or not source_root or not branch:
-            return self.respond("Missing required parameters", status=status.HTTP_400_BAD_REQUEST)
+            return self.respond(
+                {"text": "Missing required parameters"}, status=status.HTTP_400_BAD_REQUEST
+            )
 
         code_mapping = CodeMapping(
             stacktrace_root=stack_root,
diff --git a/src/sentry/integrations/utils/code_mapping.py b/src/sentry/integrations/utils/code_mapping.py
--- a/src/sentry/integrations/utils/code_mapping.py
+++ b/src/sentry/integrations/utils/code_mapping.py
@@ -5,6 +5,7 @@
 from sentry.models.integrations.repository_project_path_config import RepositoryProjectPathConfig
 from sentry.models.project import Project
 from sentry.models.repository import Repository
+from sentry.services.hybrid_cloud.integration.model import RpcOrganizationIntegration
 
 logger = logging.getLogger(__name__)
 logger.setLevel(logging.INFO)
@@ -384,7 +385,9 @@ def _potential_match(self, src_file: str, frame_filename: FrameFilename) -> bool
 
 
 def create_code_mapping(
-    organization_integration: OrganizationIntegration, project: Project, code_mapping: CodeMapping
+    organization_integration: Union[OrganizationIntegration, RpcOrganizationIntegration],
+    project: Project,
+    code_mapping: CodeMapping,
 ) -> RepositoryProjectPathConfig:
     repository, _ = Repository.objects.get_or_create(
         name=code_mapping.repo.name,


Test patch: