Skip to content

Commit 7c115f2

Browse files
authored
chore(slack): Update Tests for valid_channel_id (#73966)
Removing old Slack Client & Updating Tests
1 parent 34918d1 commit 7c115f2

File tree

7 files changed

+98
-655
lines changed

7 files changed

+98
-655
lines changed

src/sentry/integrations/slack/utils/channel.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from django.core.exceptions import ValidationError
88
from slack_sdk.errors import SlackApiError
99

10-
from sentry import features, options
10+
from sentry import features
1111
from sentry.integrations.services.integration import RpcIntegration
1212
from sentry.integrations.slack.client import SlackClient
1313
from sentry.integrations.slack.sdk_client import SlackSdkClient
@@ -96,36 +96,21 @@ def validate_channel_id(name: str, integration_id: int | None, input_channel_id:
9696
In the case that the user is creating an alert via the API and providing the channel ID and name
9797
themselves, we want to make sure both values are correct.
9898
"""
99-
# The empty string should be converted to None
100-
payload = {"channel": input_channel_id or None}
101-
102-
if options.get("slack-sdk.valid_channel_id") or integration_id in options.get(
103-
"slack-sdk.valid_channel_id_la_integration_ids"
104-
):
105-
client = SlackSdkClient(integration_id=integration_id)
106-
try:
107-
results = client.conversations_info(channel=input_channel_id).data
108-
except SlackApiError as e:
109-
if e.response["error"] == "channel_not_found":
110-
raise ValidationError("Channel not found. Invalid ID provided.") from e
111-
_logger.exception(
112-
"rule.slack.conversation_info_failed",
113-
extra={
114-
"integration_id": integration_id,
115-
"channel_name": name,
116-
"input_channel_id": input_channel_id,
117-
},
118-
)
119-
raise IntegrationError("Could not retrieve Slack channel information.") from e
120-
else:
121-
client = SlackClient(integration_id=integration_id)
122-
try:
123-
results = client.get("/conversations.info", params=payload)
124-
except ApiError as e:
125-
if e.text == "channel_not_found":
126-
raise ValidationError("Channel not found. Invalid ID provided.") from e
127-
_logger.info("rule.slack.conversation_info_failed", extra={"error": str(e)})
128-
raise IntegrationError("Could not retrieve Slack channel information.") from e
99+
100+
client = SlackSdkClient(integration_id=integration_id)
101+
try:
102+
results = client.conversations_info(channel=input_channel_id).data
103+
except SlackApiError as e:
104+
if "channel_not_found" in str(e):
105+
raise ValidationError("Channel not found. Invalid ID provided.") from e
106+
_logger.exception(
107+
"rule.slack.conversation_info_failed",
108+
extra={
109+
"integration_id": integration_id,
110+
"channel_name": name,
111+
"input_channel_id": input_channel_id,
112+
},
113+
)
129114

130115
if not isinstance(results, dict):
131116
raise IntegrationError("Bad slack channel list response.")

src/sentry/options/defaults.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,6 @@
499499
flags=FLAG_ALLOW_EMPTY | FLAG_AUTOMATOR_MODIFIABLE,
500500
)
501501

502-
503-
# Use Slack SDK in `validate_channel_id`
504-
register("slack-sdk.valid_channel_id", type=Bool, default=False, flags=FLAG_AUTOMATOR_MODIFIABLE)
505-
register(
506-
"slack-sdk.valid_channel_id_la_integration_ids", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE
507-
)
508-
509502
# Codecov Integration
510503
register("codecov.client-secret", flags=FLAG_CREDENTIAL | FLAG_PRIORITIZE_DISK)
511504

0 commit comments

Comments
 (0)