Browse Source

ref: fix typing in projectcodeowners serializer (#68618)

<!-- Describe your PR here. -->
anthony sottile 11 months ago
parent
commit
fc23419bb7
2 changed files with 9 additions and 5 deletions
  1. 0 1
      pyproject.toml
  2. 9 4
      src/sentry/api/serializers/models/projectcodeowners.py

+ 0 - 1
pyproject.toml

@@ -231,7 +231,6 @@ module = [
     "sentry.api.serializers.models.organization_member.base",
     "sentry.api.serializers.models.plugin",
     "sentry.api.serializers.models.project",
-    "sentry.api.serializers.models.projectcodeowners",
     "sentry.api.serializers.models.role",
     "sentry.api.serializers.models.rule",
     "sentry.api.serializers.models.sentry_app",

+ 9 - 4
src/sentry/api/serializers/models/projectcodeowners.py

@@ -1,7 +1,6 @@
 import logging
 from typing import Any
 
-# from sentry.api.endpoints.project_ownership import rename_schema_identifier_for_parsing
 from sentry.api.serializers import Serializer, register, serialize
 from sentry.api.serializers.models.repository_project_path_config import (
     RepositoryProjectPathConfigSerializer,
@@ -22,6 +21,8 @@ class ProjectCodeOwnersSerializer(Serializer):
         self.expand = expand or []
 
     def get_attrs(self, item_list, user, **kwargs):
+        from sentry.integrations.mixins import RepositoryMixin  # XXX: circular import
+
         attrs = {}
         integrations = {
             i.id: i
@@ -37,11 +38,15 @@ class ProjectCodeOwnersSerializer(Serializer):
                 organization_id=item.repository_project_path_config.organization_id,
             )
             codeowners_url = "unknown"
-            if item.repository_project_path_config.organization_integration_id:
+            if item.repository_project_path_config.organization_integration_id and isinstance(
+                install, RepositoryMixin
+            ):
                 try:
-                    codeowners_url = install.get_codeowner_file(
+                    codeowners_response = install.get_codeowner_file(
                         code_mapping.repository, ref=code_mapping.default_branch
-                    )["html_url"]
+                    )
+                    if codeowners_response is not None:
+                        codeowners_url = codeowners_response["html_url"]
 
                 except Exception:
                     logger.exception("Could not get CODEOWNERS URL. Continuing execution.")