Skip to content
Draft
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
8 changes: 6 additions & 2 deletions scripts/backfillReportingChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 10 additions & 2 deletions src/slack/findSlackChannelByName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebClient, 'paginate'>,
slack: Pick<WebClient, 'paginate'>,
configuredChannelId: string | null,
channelName: string,
): Promise<string | null> {
return configuredChannelId;
if (configuredChannelId) return configuredChannelId;

const channel = await findSlackChannelByName(slack, channelName);
return channel?.id ?? null;
}
Loading