Skip to content

Commit

Permalink
fix(suspect-commits): get active integrations (#77174)
Browse files Browse the repository at this point in the history
  • Loading branch information
cathteng committed Sep 9, 2024
1 parent 1f23abd commit 78fc49d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/sentry/integrations/utils/commit_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tests/sentry/tasks/test_commit_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -27,13 +28,15 @@
)
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,
queue_comment_task_if_needed,
)
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

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 78fc49d

Please sign in to comment.