Просмотр исходного кода

ref(derived_code_mappings): Minor touches (#41199)

Armen Zambrano G 2 лет назад
Родитель
Сommit
be7312cca8

+ 4 - 4
src/sentry/integrations/github/client.py

@@ -97,20 +97,20 @@ class GitHubClientMixin(ApiClient):  # type: ignore
             if msg == "Git Repository is empty.":
                 logger.warning(f"{repo_full_name} is empty.")
             elif msg == "Not Found":
-                logger.error(f"The Github App does not have access to {repo_full_name}.")
+                logger.warning(f"The Github App does not have access to {repo_full_name}.")
             else:
-                sentry_sdk.capture_exception(e)
+                logger.exception("An unknown error has ocurred.")
 
         return tree
 
     def get_trees_for_org(
-        self, org_slug: str, gh_org: str, cache_seconds: int = 3600 * 24
+        self, cache_key: str, gh_org: str, cache_seconds: int = 3600 * 24
     ) -> Dict[str, RepoTree]:
         """
         This fetches tree representations of all repos for an org.
         """
         trees: Dict[str, RepoTree] = {}
-        cache_key = f"githubtrees:repositories:{org_slug}:{gh_org}"
+        cache_key = f"githubtrees:repositories:{cache_key}:{gh_org}"
         repo_key = "githubtrees:repo"
         cached_repositories = cache.get(cache_key, [])
         if not cached_repositories:

+ 1 - 1
src/sentry/integrations/github/integration.py

@@ -109,7 +109,7 @@ class GitHubIntegration(IntegrationInstallation, GitHubIssueBasic, RepositoryMix
     def get_trees_for_org(self, cache_seconds: int = 3600 * 24) -> JSONData:
         gh_org = self.model.metadata["domain_name"].split("github.com/")[1]
         return self.get_client().get_trees_for_org(
-            org_slug=self.org_integration.organization.slug,
+            cache_key=self.org_integration.organization.slug,
             gh_org=gh_org,
             cache_seconds=cache_seconds,
         )

+ 1 - 1
src/sentry/tasks/derive_code_mappings.py

@@ -43,6 +43,7 @@ def derive_code_mappings(
     set_tag("organization.slug", organization.slug)
     # When you look at the performance page the user is a default column
     set_user({"username": organization.slug})
+    set_tag("project.slug", project.slug)
 
     # Check the feature flag again to ensure the feature is still enabled.
     should_continue = features.has(
@@ -176,7 +177,6 @@ def report_project_codemappings(
     """
     Log the code mappings that would be created for a project.
     """
-    set_tag("project.slug", project.slug)
     extra = {
         "org": project.organization.slug,
         "project": project.slug,

+ 1 - 1
tests/sentry/integrations/github/test_integration.py

@@ -604,7 +604,7 @@ class GitHubIntegrationTest(IntegrationTestCase):
             # These checks are useful since they will be available in the GCP logs
             expected_msg = "The Github App does not have access to Test-Organization/baz."
             assert self._caplog.records[8].message == expected_msg
-            assert self._caplog.records[8].levelname == "ERROR"
+            assert self._caplog.records[8].levelname == "WARNING"
             # XXX: We would need to patch timezone to make sure the time is always the same
             assert self._caplog.records[9].message.startswith("Caching trees for Test-Organization")
             assert self._caplog.records[9].levelname == "INFO"