From 78fc49d12fa1b9f09d926525c540528d34136d6f Mon Sep 17 00:00:00 2001 From: Cathy Teng <70817427+cathteng@users.noreply.github.com> Date: Mon, 9 Sep 2024 12:39:48 -0700 Subject: [PATCH] fix(suspect-commits): get active integrations (#77174) --- .../integrations/utils/commit_context.py | 4 ++- tests/sentry/tasks/test_commit_context.py | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/sentry/integrations/utils/commit_context.py b/src/sentry/integrations/utils/commit_context.py index 3b0c3d5a900b8d..bdd64acc18ef7a 100644 --- a/src/sentry/integrations/utils/commit_context.py +++ b/src/sentry/integrations/utils/commit_context.py @@ -9,6 +9,7 @@ from django.utils.datastructures import OrderedSet from sentry import analytics +from sentry.constants import ObjectStatus from sentry.integrations.base import IntegrationInstallation from sentry.integrations.models.repository_project_path_config import RepositoryProjectPathConfig from sentry.integrations.services.integration import integration_service @@ -262,8 +263,9 @@ def _get_blames_from_all_integrations( integration_to_install_mapping: dict[str, tuple[IntegrationInstallation, str]] = {} for integration_organization_id, files in integration_to_files_mapping.items(): + # find active integrations, otherwise integration proxy will not send request integration = integration_service.get_integration( - organization_integration_id=integration_organization_id + organization_integration_id=integration_organization_id, status=ObjectStatus.ACTIVE ) if not integration: continue diff --git a/tests/sentry/tasks/test_commit_context.py b/tests/sentry/tasks/test_commit_context.py index 2073c86387f351..6eb7ad79dfbbfa 100644 --- a/tests/sentry/tasks/test_commit_context.py +++ b/tests/sentry/tasks/test_commit_context.py @@ -8,6 +8,7 @@ from celery.exceptions import Retry from django.utils import timezone +from sentry.constants import ObjectStatus from sentry.integrations.github.integration import GitHubIntegrationProvider from sentry.integrations.services.integration import integration_service from sentry.integrations.source_code_management.commit_context import ( @@ -27,6 +28,7 @@ ) from sentry.models.repository import Repository from sentry.shared_integrations.exceptions import ApiError +from sentry.silo.base import SiloMode from sentry.tasks.commit_context import ( PR_COMMENT_WINDOW, process_commit_context, @@ -34,6 +36,7 @@ ) from sentry.testutils.cases import IntegrationTestCase, TestCase from sentry.testutils.helpers.datetime import before_now, iso_format +from sentry.testutils.silo import assume_test_silo_mode from sentry.testutils.skips import requires_snuba from sentry.utils.committers import get_frame_paths @@ -159,6 +162,37 @@ def setUp(self): ), ) + @patch( + "sentry.integrations.github.GitHubIntegration.get_commit_context_all_frames", + ) + def test_inactive_integration(self, mock_get_commit_context): + """ + Early return if the integration is not active + """ + with assume_test_silo_mode(SiloMode.CONTROL): + self.integration.update(status=ObjectStatus.DISABLED) + + with self.tasks(): + assert not GroupOwner.objects.filter(group=self.event.group).exists() + existing_commit = self.create_commit( + project=self.project, + repo=self.repo, + author=self.commit_author, + key="existing-commit", + ) + existing_commit.update(message="") + assert Commit.objects.count() == 2 + event_frames = get_frame_paths(self.event) + process_commit_context( + event_id=self.event.event_id, + event_platform=self.event.platform, + event_frames=event_frames, + group_id=self.event.group_id, + project_id=self.event.project_id, + ) + + assert not mock_get_commit_context.called + @patch("sentry.analytics.record") @patch( "sentry.integrations.github.GitHubIntegration.get_commit_context_all_frames",