Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(slack): channel api deprecated #19446

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/sentry/integrations/slack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.core.urlresolvers import reverse

from sentry import tagstore
from sentry import options
from sentry.api.fields.actor import Actor
from sentry.incidents.logic import get_incident_aggregates
from sentry.incidents.models import IncidentStatus, IncidentTrigger
Expand Down Expand Up @@ -373,11 +374,12 @@ def build_incident_attachment(incident, metric_value=None):

# Different list types in slack that we'll use to resolve a channel name. Format is
# (<list_name>, <result_name>, <prefix>).
LIST_TYPES = [
LEGACY_LIST_TYPES = [
("channels", "channels", CHANNEL_PREFIX),
("groups", "groups", CHANNEL_PREFIX),
("users", "members", MEMBER_PREFIX),
]
LIST_TYPES = [("conversations", "channels", CHANNEL_PREFIX), ("users", "members", MEMBER_PREFIX)]


def strip_channel_name(name):
Expand Down Expand Up @@ -418,12 +420,18 @@ def get_channel_id_with_timeout(integration, name, timeout):
# Look for channel ID
payload = dict(token_payload, **{"exclude_archived": False, "exclude_members": True})

if options.get("slack.legacy-app") is True:
list_types = LEGACY_LIST_TYPES
else:
list_types = LIST_TYPES
payload = dict(payload, **{"types": "public_channel,private_channel"})

time_to_quit = time.time() + timeout

client = SlackClient()
id_data = None
found_duplicate = False
for list_type, result_name, prefix in LIST_TYPES:
for list_type, result_name, prefix in list_types:
cursor = ""
while True:
endpoint = "/%s.list" % list_type
Expand Down
1 change: 1 addition & 0 deletions src/sentry/options/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
register("slack.client-secret", flags=FLAG_PRIORITIZE_DISK)
register("slack.verification-token", flags=FLAG_PRIORITIZE_DISK)
register("slack.signing-secret", flags=FLAG_PRIORITIZE_DISK)
register("slack.legacy-app", flags=FLAG_PRIORITIZE_DISK, type=Bool, default=True)

# Slack V2 Integration
register("slack-v2.client-id", flags=FLAG_PRIORITIZE_DISK)
Expand Down
1 change: 1 addition & 0 deletions src/sentry/utils/pytest/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def pytest_configure(config):
"slack.client-id": "slack-client-id",
"slack.client-secret": "slack-client-secret",
"slack.verification-token": "slack-verification-token",
"slack.legacy-app": True,
"github-app.name": "sentry-test-app",
"github-app.client-id": "github-client-id",
"github-app.client-secret": "github-client-secret",
Expand Down