Skip to content

Attempt automatic Slack channel conversion on incident visibility change - #317

Merged
rgibert merged 4 commits into
mainfrom
richard/releng-1052-slack-visibility-conversion
Sep 17, 2026
Merged

rgibert merged 4 commits into
mainfrom
richard/releng-1052-slack-visibility-conversion

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Fixes RELENG-1052.

Problem

When an incident's visibility (private/public) changes, on_visibility_changed (and the equivalent path in on_incident_updated) always posted a message telling users a Slack admin has to convert the channel manually. It never actually attempted to convert the channel — that's why #inc-2518 had to be fixed by hand.

Fix

  • Add SlackService.convert_channel_privacy(channel_id, is_private), which calls Slack's admin API (admin.conversations.convertToPublic / admin.conversations.convertToPrivate) to attempt the conversion.
  • In both visibility-change code paths, try the conversion first:
    • On success, post a confirmation message ("...and this channel has been converted to public/private").
    • On failure (e.g. missing admin.conversations:write scope — the likely reason this was never automated, matching Richard's diagnosis in #team-sre), fall back to the existing manual-conversion message, so behavior for orgs without that admin scope is unchanged.

This requires the Slack app to have admin.conversations:write (Enterprise Grid org-installed) to actually auto-convert; without it, Firetower degrades gracefully to today's manual-fallback behavior.

Testing

  • uv run pytest — full suite passes except one pre-existing unrelated failure (TestOnIncidentCreated::test_creates_channel_and_link, also fails on main).
  • uv run ruff check / ruff format --check / mypy src — all clean.
  • Added unit tests for SlackService.convert_channel_privacy (success, no client, API error fallback) and updated on_visibility_changed tests to cover both the conversion-succeeds and conversion-fails paths.

via Richard Gibert.

--

View Junior Session [Sentry]

When an incident's visibility changes, Firetower always posted a message
telling users a Slack admin has to convert the channel manually. It never
actually tried to convert the channel.

Add SlackService.convert_channel_privacy(), which uses the Slack admin
API (admin.conversations.convertToPublic/convertToPrivate) to attempt the
conversion. If it succeeds, post a confirmation message instead of the
manual-conversion notice. If it fails (e.g. missing admin scope, which is
the likely reason this was never automated), fall back to the existing
manual-conversion message so behavior is unchanged for orgs without the
required Slack app scope.

Fixes RELENG-1052.

Co-Authored-By: Richard Gibert <richard.gibert@sentry.io>
@linear-code

linear-code Bot commented Sep 9, 2026

Copy link
Copy Markdown

RELENG-1052

Comment thread src/firetower/incidents/hooks.py Outdated
Warden flagged that toggling incident visibility called the Slack admin
convert APIs on the channel ID parsed from the incident's writable Slack
external link, with no ownership check. Any authenticated user who can
edit a visible incident could point that link at an arbitrary workspace
channel and force it public/private once the bot has admin.conversations
scope.

Add _is_incidents_own_channel(), which fetches the channel's real name via
Slack and requires it to match the incident's canonical channel name
(build_channel_name) before allowing the admin conversion call. Falls back
to the existing manual-conversion message when the channel doesn't match.
@rgibert
rgibert marked this pull request as ready for review September 9, 2026 18:46
@rgibert
rgibert requested a review from a team as a code owner September 9, 2026 18:46
Comment thread src/firetower/integrations/services/slack.py
@rgibert
rgibert enabled auto-merge (squash) September 17, 2026 15:18
@rgibert
rgibert merged commit d8590d3 into main Sep 17, 2026
25 checks passed
@rgibert
rgibert deleted the richard/releng-1052-slack-visibility-conversion branch September 17, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants