Skip to content

Commit

Permalink
ref: remove dead code in integrations files (#83743)
Browse files Browse the repository at this point in the history
<!-- Describe your PR here. -->
  • Loading branch information
asottile-sentry authored Jan 22, 2025
1 parent d771d06 commit 952cde0
Show file tree
Hide file tree
Showing 35 changed files with 45 additions and 293 deletions.
7 changes: 0 additions & 7 deletions src/sentry/integrations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ class IntegrationProviderSlug(StrEnum):
],
}

INTEGRATION_PROVIDER_TO_TYPE = {
v: k for k, values in INTEGRATION_TYPE_TO_PROVIDER.items() for v in values
}


class IntegrationProvider(PipelineProvider, abc.ABC):
"""
Expand Down Expand Up @@ -518,9 +514,6 @@ def uninstall(self) -> None:
def notify_remove_external_team(self, external_team: ExternalActor, team: Team) -> None:
pass

def remove_notification_settings(self, actor_id: int, provider: str) -> None:
pass


def is_response_success(resp: Any) -> bool:
if resp.status_code and resp.status_code < 300:
Expand Down
1 change: 0 additions & 1 deletion src/sentry/integrations/bitbucket/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class BitbucketAPIPath:

repository = "/2.0/repositories/{repo}"
repositories = "/2.0/repositories/{username}"
repository_commit = "/2.0/repositories/{repo}/commit/{sha}"
repository_commits = "/2.0/repositories/{repo}/commits/{revision}"
repository_diff = "/2.0/repositories/{repo}/diff/{spec}"
repository_hook = "/2.0/repositories/{repo}/hooks/{uid}"
Expand Down
1 change: 0 additions & 1 deletion src/sentry/integrations/bitbucket_server/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class BitbucketServerAPIPath:
repository_hook = "/rest/api/1.0/projects/{project}/repos/{repo}/webhooks/{id}"
repository_hooks = "/rest/api/1.0/projects/{project}/repos/{repo}/webhooks"
repository_commits = "/rest/api/1.0/projects/{project}/repos/{repo}/commits"
repository_commit_details = "/rest/api/1.0/projects/{project}/repos/{repo}/commits/{commit}"
commit_changes = "/rest/api/1.0/projects/{project}/repos/{repo}/commits/{commit}/changes"


Expand Down
2 changes: 0 additions & 2 deletions src/sentry/integrations/discord/message_builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@
"Warning": "warning",
"Critical": "fatal",
}

DISCORD_URL_FORMAT = "[{text}]({url})"
10 changes: 0 additions & 10 deletions src/sentry/integrations/discord/message_builder/base/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Discord message flags.
# See: https://discord.com/developers/docs/resources/channel#message-object-message-flags
EPHEMERAL_FLAG = 1 << 6
LOADING_FLAG = 1 << 7
SUPPRESS_NOTIFICATIONS_FLAG = 1 << 12


class DiscordMessageFlags:
Expand All @@ -23,11 +21,3 @@ def __init__(self):
def set_ephemeral(self) -> DiscordMessageFlags:
self.value = self.value | EPHEMERAL_FLAG
return self

def set_loading(self) -> DiscordMessageFlags:
self.value = self.value | LOADING_FLAG
return self

def set_suppress_notifications(self) -> DiscordMessageFlags:
self.value = self.value | SUPPRESS_NOTIFICATIONS_FLAG
return self
3 changes: 0 additions & 3 deletions src/sentry/integrations/discord/requests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,6 @@ def is_command(self) -> bool:
def is_message_component(self) -> bool:
return self._data.get("type", 0) == DiscordRequestTypes.MESSAGE_COMPONENT

def is_modal_submit(self) -> bool:
return self._data.get("type", 0) == DiscordRequestTypes.MODAL_SUBMIT

def get_command_name(self) -> str:
if not self.is_command():
return ""
Expand Down
8 changes: 0 additions & 8 deletions src/sentry/integrations/github/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,6 @@ def get_pullrequest_from_commit(self, repo: str, sha: str) -> Any:
"""
return self.get(f"/repos/{repo}/commits/{sha}/pulls")

def get_pullrequest(self, repo: str, pull_number: str) -> Any:
"""
https://docs.github.com/en/rest/pulls/pulls#get-a-pull-request
Returns the pull request details
"""
return self.get(f"/repos/{repo}/pulls/{pull_number}")

def get_pullrequest_files(self, repo: str, pull_number: str) -> Any:
"""
https://docs.github.com/en/rest/pulls/pulls#list-pull-requests-files
Expand Down
1 change: 0 additions & 1 deletion src/sentry/integrations/gitlab/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class GitLabApiClientPath:
project_issues = "/projects/{project}/issues"
project_hooks = "/projects/{project}/hooks"
project_hook = "/projects/{project}/hooks/{hook_id}"
project_search = "/projects/{project}/search"
projects = "/projects"
user = "/user"

Expand Down
46 changes: 20 additions & 26 deletions src/sentry/integrations/messaging/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,37 +67,31 @@ def __init__(
def name(self) -> str:
return self.interaction_type.value

@staticmethod
def _to_tokens(text: str) -> tuple[str, ...]:
return tuple(token.casefold() for token in text.strip().split())

def get_all_command_slugs(self) -> Iterable[CommandSlug]:
yield self.command_slug
yield from self.aliases


MESSAGING_INTEGRATION_COMMANDS = (
HELP := MessagingIntegrationCommand(
MessagingInteractionType.HELP,
"help",
aliases=("", "support", "docs"),
),
LINK_IDENTITY := MessagingIntegrationCommand(
MessagingInteractionType.LINK_IDENTITY,
"link",
),
UNLINK_IDENTITY := MessagingIntegrationCommand(
MessagingInteractionType.UNLINK_IDENTITY,
"unlink",
),
LINK_TEAM := MessagingIntegrationCommand(
MessagingInteractionType.LINK_TEAM,
"link team",
),
UNLINK_TEAM := MessagingIntegrationCommand(
MessagingInteractionType.UNLINK_TEAM,
"unlink team",
),
HELP = MessagingIntegrationCommand(
MessagingInteractionType.HELP,
"help",
aliases=("", "support", "docs"),
)
LINK_IDENTITY = MessagingIntegrationCommand(
MessagingInteractionType.LINK_IDENTITY,
"link",
)
UNLINK_IDENTITY = MessagingIntegrationCommand(
MessagingInteractionType.UNLINK_IDENTITY,
"unlink",
)
LINK_TEAM = MessagingIntegrationCommand(
MessagingInteractionType.LINK_TEAM,
"link team",
)
UNLINK_TEAM = MessagingIntegrationCommand(
MessagingInteractionType.UNLINK_TEAM,
"unlink team",
)

R = TypeVar("R") # response
Expand Down
11 changes: 0 additions & 11 deletions src/sentry/integrations/middleware/hybrid_cloud/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,6 @@ def get_response_from_webhookpayload(

return HttpResponse(status=status.HTTP_202_ACCEPTED)

def get_response_from_webhookpayload_for_integration(
self, regions: Sequence[Region], integration: Integration | RpcIntegration
):
"""
Used to create outboxes for provided regions to handle the webhooks asynchronously.
Responds to the webhook provider with a 202 Accepted status.
"""
return self.get_response_from_webhookpayload(
regions=regions, identifier=integration.id, integration_id=integration.id
)

def get_mailbox_identifier(
self, integration: RpcIntegration | Integration, data: Mapping[str, Any]
) -> str:
Expand Down
7 changes: 0 additions & 7 deletions src/sentry/integrations/models/external_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from sentry.eventstore.models import Event

if TYPE_CHECKING:
from django.db.models.query import _QuerySet

from sentry.integrations.services.integration import RpcIntegration


Expand Down Expand Up @@ -54,11 +52,6 @@ def get_linked_issues(
integration_id=integration.id,
)

def get_linked_issue_ids(
self, event: Event, integration: RpcIntegration
) -> _QuerySet[ExternalIssue, str]:
return self.get_linked_issues(event, integration).values_list("key", flat=True)

def has_linked_issue(self, event: Event, integration: RpcIntegration) -> bool:
return self.get_linked_issues(event, integration).exists()

Expand Down
14 changes: 1 addition & 13 deletions src/sentry/integrations/models/integration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import logging
from typing import TYPE_CHECKING, Any, ClassVar
from typing import TYPE_CHECKING, Any

from django.db import IntegrityError, models, router, transaction

Expand All @@ -15,7 +15,6 @@
control_silo_model,
)
from sentry.db.models.fields.jsonfield import JSONField
from sentry.db.models.manager.base import BaseManager
from sentry.hybridcloud.models.outbox import ControlOutbox, outbox_context
from sentry.hybridcloud.outbox.category import OutboxCategory, OutboxScope
from sentry.integrations.models.organization_integration import OrganizationIntegration
Expand All @@ -36,15 +35,6 @@
logger = logging.getLogger(__name__)


class IntegrationManager(BaseManager["Integration"]):
def get_active_integrations(self, organization_id: str):
return self.filter(
status=ObjectStatus.ACTIVE,
organizationintegration__status=ObjectStatus.ACTIVE,
organizationintegration__organization_id=organization_id,
)


@control_silo_model
class Integration(DefaultFieldsModelExisting):
"""
Expand All @@ -65,8 +55,6 @@ class Integration(DefaultFieldsModelExisting):
default=ObjectStatus.ACTIVE, choices=ObjectStatus.as_choices(), null=True
)

objects: ClassVar[IntegrationManager] = IntegrationManager()

class Meta:
app_label = "sentry"
db_table = "sentry_integration"
Expand Down
3 changes: 0 additions & 3 deletions src/sentry/integrations/msteams/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ class MsTeamsClientMixin:
CONVERSATION_URL = "/v3/conversations"
MEMBER_URL = "/v3/conversations/%s/pagedmembers"

def get_team_info(self, team_id: str):
return self.get(self.TEAM_URL % team_id)

def get_channel_list(self, team_id: str):
resp = self.get(self.CHANNEL_URL % team_id)
return resp.get("conversations")
Expand Down
23 changes: 0 additions & 23 deletions src/sentry/integrations/services/integration/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,6 @@ def page_integration_ids(
),
)

def page_organization_integrations_ids(
self,
*,
organization_id: int,
statuses: list[int],
provider_key: str | None = None,
args: RpcPaginationArgs,
) -> RpcPaginationResult:
queryset = OrganizationIntegration.objects.filter(
organization_id=organization_id,
status__in=statuses,
)

if provider_key:
queryset = queryset.filter(integration__provider=provider_key.lower())

return args.do_hybrid_cloud_pagination(
description="page_organization_integrations_ids",
paginator_cls=OffsetPaginator,
order_by="integration__name",
queryset=queryset,
)

def get_integrations(
self,
*,
Expand Down
12 changes: 0 additions & 12 deletions src/sentry/integrations/services/integration/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ def send_message(
) -> bool:
pass

@rpc_method
@abstractmethod
def page_organization_integrations_ids(
self,
*,
organization_id: int,
statuses: list[int],
provider_key: str | None = None,
args: RpcPaginationArgs,
) -> RpcPaginationResult:
pass

@rpc_method
@abstractmethod
def get_integrations(
Expand Down
10 changes: 0 additions & 10 deletions src/sentry/integrations/services/repository/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@ def update_repository(self, *, organization_id: int, update: RpcRepository) -> N

repository.save()

def reinstall_repositories_for_integration(
self, *, organization_id: int, integration_id: int, provider: str
) -> None:
with transaction.atomic(router.db_for_write(Repository)):
Repository.objects.filter(
organization_id=organization_id,
integration_id=integration_id,
provider=provider,
).update(status=ObjectStatus.ACTIVE)

def disable_repositories_for_integration(
self, *, organization_id: int, integration_id: int, provider: str
) -> None:
Expand Down
9 changes: 0 additions & 9 deletions src/sentry/integrations/services/repository/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ def create_repository(
def update_repository(self, *, organization_id: int, update: RpcRepository) -> None:
pass

@regional_rpc_method(resolve=ByOrganizationId())
@abstractmethod
def reinstall_repositories_for_integration(
self, *, organization_id: int, integration_id: int, provider: str
) -> None:
"""
Reinstalls all repositories associated with the given integration by marking them as active.
"""

@regional_rpc_method(resolve=ByOrganizationId())
@abstractmethod
def disable_repositories_for_integration(
Expand Down
21 changes: 0 additions & 21 deletions src/sentry/integrations/slack/message_builder/base/base.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
from __future__ import annotations

from abc import ABC
from collections.abc import Mapping, MutableMapping
from typing import Any

from sentry.eventstore.models import Event, GroupEvent
from sentry.integrations.slack.message_builder.types import SlackBody
from sentry.models.group import Group
from sentry.notifications.utils.actions import MessageAction


def get_slack_button(action: MessageAction) -> Mapping[str, Any]:
kwargs: MutableMapping[str, Any] = {
"text": action.label or action.name,
"name": action.name,
"type": action.type,
}
for field in ("style", "url", "value", "action_id"):
value = getattr(action, field, None)
if value:
kwargs[field] = value

if action.type == "select":
kwargs["selected_options"] = action.selected_options or []
kwargs["option_groups"] = action.option_groups or []

return kwargs


class SlackMessageBuilder(ABC):
Expand Down
9 changes: 0 additions & 9 deletions src/sentry/integrations/slack/message_builder/base/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ def get_tags_block(
def get_divider() -> SlackBlock:
return {"type": "divider"}

@staticmethod
def get_static_action(action):
return {
"type": "static_select",
"placeholder": {"type": "plain_text", "text": action.label, "emoji": True},
"option_groups": [option for option in action.option_groups],
"action_id": action.name,
}

@staticmethod
def get_external_select_action(action, initial_option):
action = {
Expand Down
2 changes: 0 additions & 2 deletions src/sentry/integrations/slack/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
SLACK_ISSUE_ALERT_FAILURE_DATADOG_METRIC = "sentry.integrations.slack.issue_alert.failure"

# Webhooks
SLACK_WEBHOOK_DM_ENDPOINT_SUCCESS_DATADOG_METRIC = "sentry.integrations.slack.dm_endpoint.success"
SLACK_WEBHOOK_DM_ENDPOINT_FAILURE_DATADOG_METRIC = "sentry.integrations.slack.dm_endpoint.failure"
SLACK_WEBHOOK_EVENT_ENDPOINT_SUCCESS_DATADOG_METRIC = (
"sentry.integrations.slack.event_endpoint.success"
)
Expand Down
1 change: 0 additions & 1 deletion src/sentry/integrations/slack/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from sentry.utils import metrics

logger = logging.getLogger("sentry.notifications")
SLACK_TIMEOUT = 5


class SlackNotifyBasicMixin(NotifyBasicMixin):
Expand Down
Loading

0 comments on commit 952cde0

Please sign in to comment.