diff --git a/scripts/backfillReportingChannel.ts b/scripts/backfillReportingChannel.ts index 97011e4..693ef7e 100644 --- a/scripts/backfillReportingChannel.ts +++ b/scripts/backfillReportingChannel.ts @@ -55,11 +55,15 @@ async function main() { try { const slack = getSlackClientForEvent(event); - const channelId = await resolveSlackChannelId(slack, event.slackReportingChannelId); + const channelId = await resolveSlackChannelId( + slack, + force ? null : event.slackReportingChannelId, + channelName, + ); if (!channelId) { skippedNotFound += 1; - console.log(`- ${event.id}: no configured reporting channel ID, skipping`); + console.log(`- ${event.id}: could not find #${channelName} in this workspace, skipping`); continue; } diff --git a/src/slack/findSlackChannelByName.ts b/src/slack/findSlackChannelByName.ts index 305ab54..2b108b5 100644 --- a/src/slack/findSlackChannelByName.ts +++ b/src/slack/findSlackChannelByName.ts @@ -27,9 +27,17 @@ export async function findSlackChannelByName( )); } +/** + * Returns the channel ID to use for reporting: the already-configured ID if + * one is set, otherwise looks up `channelName` in the workspace by name. + */ export async function resolveSlackChannelId( - _slack: Pick, + slack: Pick, configuredChannelId: string | null, + channelName: string, ): Promise { - return configuredChannelId; + if (configuredChannelId) return configuredChannelId; + + const channel = await findSlackChannelByName(slack, channelName); + return channel?.id ?? null; } \ No newline at end of file