From 419c0b1c29c8e52d110c5ff2e795558c5c84ddbf Mon Sep 17 00:00:00 2001 From: Florent LE BOULCH Date: Fri, 14 Jun 2024 15:57:54 +0200 Subject: [PATCH] feat: make support channel configurable --- .env.test | 2 ++ README.md | 8 ++++++ __tests__/review/displayHelpMessage.test.ts | 30 +++++++++++++++++++++ config/homer/projectReleaseConfigs.ts | 6 ++--- src/constants.ts | 8 +++++- src/core/viewBuilders/buildHelpMessage.ts | 9 ++++--- src/home/buildAppHomeView.ts | 4 +-- 7 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 __tests__/review/displayHelpMessage.test.ts diff --git a/.env.test b/.env.test index 23d95ff..0730576 100644 --- a/.env.test +++ b/.env.test @@ -12,4 +12,6 @@ POSTGRES_PORT=54320 POSTGRES_USER=root SLACK_BOT_USER_O_AUTH_ACCESS_TOKEN=SLACK_BOT_USER_O_AUTH_ACCESS_TOKEN SLACK_SIGNING_SECRET=SLACK_SIGNING_SECRET +SLACK_SUPPORT_CHANNEL_ID=C0XXXXXXXXX +SLACK_SUPPORT_CHANNEL_NAME=support-homer TICKET_MANAGEMENT_URL_PATTERN=https://my-ticket-management.com/view/{ticketId} diff --git a/README.md b/README.md index 4d3bd4e..1057b59 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,14 @@ Create a `.env` file containing the following variables: The ticket management URL pattern for your organization, this is used to generate a link to the ticket in the changelog. It must contain the `{ticketId}` matcher to be replaced by the ticket ID, for instance `https://my-ticket-management.com/view/{ticketId}`. +- `SLACK_SUPPORT_CHANNEL_ID` + + This slack channel id is displayed when a user enters the help command. People having trouble with homer can be helped on this support channel. + +- `SLACK_SUPPORT_CHANNEL_NAME` + + This slack channel name is displayed when a user enters the help command. People having trouble with homer can be helped on this support channel. + If you want Homer to connect to an **external PostgreSQL database**, you can set the following variables: diff --git a/__tests__/review/displayHelpMessage.test.ts b/__tests__/review/displayHelpMessage.test.ts new file mode 100644 index 0000000..c505745 --- /dev/null +++ b/__tests__/review/displayHelpMessage.test.ts @@ -0,0 +1,30 @@ +import { HTTP_STATUS_OK } from '@/constants'; +import { fetch } from '../utils/fetch'; +import { getSlackHeaders } from '../utils/getSlackHeaders'; + +describe('help', () => { + it('help message should be displayed', async () => { + // Given + const channelId = 'channelId'; + const userId = 'userId'; + const body = { + channel_id: channelId, + text: 'help', + user_id: userId, + }; + + // When + const response = await fetch('/api/v1/homer/command', { + body, + headers: getSlackHeaders(body), + }); + const slackMessage = await response.json(); + + // Then + expect(response.status).toEqual(HTTP_STATUS_OK); + expect(slackMessage.text).toContain('Here are the available commands:'); + expect(slackMessage.text).toContain( + "Don't hesitate to join me on #support-homer to take a beer!" + ); + }); +}); diff --git a/config/homer/projectReleaseConfigs.ts b/config/homer/projectReleaseConfigs.ts index 11413f7..ed9de02 100644 --- a/config/homer/projectReleaseConfigs.ts +++ b/config/homer/projectReleaseConfigs.ts @@ -1,4 +1,4 @@ -import { MOES_TAVERN_CHANNEL_ID } from '@/constants'; +import { SLACK_SUPPORT_CHANNEL_ID } from '@/constants'; import { defaultReleaseManager } from '@/release/commands/create/managers/defaultReleaseManager'; import { stableDateReleaseTagManager } from '@/release/commands/create/managers/stableDateReleaseTagManager'; import type { ProjectReleaseConfig } from '@/release/typings/ProjectReleaseConfig'; @@ -6,9 +6,9 @@ import type { ProjectReleaseConfig } from '@/release/typings/ProjectReleaseConfi export const projectReleaseConfigs: ProjectReleaseConfig[] = [ // tools/homer { - notificationChannelIds: [MOES_TAVERN_CHANNEL_ID], + notificationChannelIds: [SLACK_SUPPORT_CHANNEL_ID], projectId: 1148, - releaseChannelId: MOES_TAVERN_CHANNEL_ID, + releaseChannelId: SLACK_SUPPORT_CHANNEL_ID, releaseManager: defaultReleaseManager, releaseTagManager: stableDateReleaseTagManager, }, diff --git a/src/constants.ts b/src/constants.ts index 3935b48..b784dc5 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,5 @@ import type { GitlabMergeRequestState } from '@/core/typings/GitlabMergeRequest'; +import { getEnvVariable } from '@/core/utils/getEnvVariable'; export const CHANNEL_NOT_FOUND_SLACK_ERROR = 'channel_not_found'; export const EXPIRED_TRIGGER_ID_ERROR_MESSAGE = @@ -18,7 +19,12 @@ export const MERGE_REQUEST_OPEN_STATES: GitlabMergeRequestState[] = [ 'opened', 'reopened', ]; -export const MOES_TAVERN_CHANNEL_ID = 'C01FCCQGP3M'; +export const SLACK_SUPPORT_CHANNEL_ID = getEnvVariable( + 'SLACK_SUPPORT_CHANNEL_ID' +); +export const SLACK_SUPPORT_CHANNEL_NAME = getEnvVariable( + 'SLACK_SUPPORT_CHANNEL_NAME' +); export const PRIVATE_CHANNEL_ERROR_MESSAGE = 'D’oh! It looks like you tried to use me on a private channel I’m not in. Please invite me using `/invite @homer` so I can publish messages :homer-donut:'; export const REQUEST_BODY_SIZE_LIMIT = '500kb'; diff --git a/src/core/viewBuilders/buildHelpMessage.ts b/src/core/viewBuilders/buildHelpMessage.ts index 07b0580..fb944b3 100644 --- a/src/core/viewBuilders/buildHelpMessage.ts +++ b/src/core/viewBuilders/buildHelpMessage.ts @@ -1,5 +1,8 @@ import type { ChatPostMessageArguments } from '@slack/web-api'; -import { MOES_TAVERN_CHANNEL_ID } from '@/constants'; +import { + SLACK_SUPPORT_CHANNEL_ID, + SLACK_SUPPORT_CHANNEL_NAME, +} from '@/constants'; export function buildHelpMessage(channelId: string): ChatPostMessageArguments { return { @@ -14,7 +17,7 @@ Here are the available commands: - /homer review <search> - Share a merge request on a channel. Searches in title and description by default. Accepts merge request URLs and merge request IDs prefixed with "!". - /homer review list - List ongoing reviews shared in a channel. -Don't hesitate to join me on #moes-tavern-homer to take a beer!`, +Don't hesitate to join me on #${SLACK_SUPPORT_CHANNEL_NAME} to take a beer!`, blocks: [ { type: 'section', @@ -30,7 +33,7 @@ Here are the available commands: • \`/homer review <search>\` Share a merge request on a channel. Searches in title and description by default. Accepts merge request URLs and merge request IDs prefixed with "!". • \`/homer review list\` List ongoing reviews shared in a channel. -Don't hesitate to join me on <#${MOES_TAVERN_CHANNEL_ID}> to take a :beer:!`, +Don't hesitate to join me on <#${SLACK_SUPPORT_CHANNEL_ID}> to take a :beer:!`, }, }, ], diff --git a/src/home/buildAppHomeView.ts b/src/home/buildAppHomeView.ts index e582a2a..5fa883e 100644 --- a/src/home/buildAppHomeView.ts +++ b/src/home/buildAppHomeView.ts @@ -1,5 +1,5 @@ import type { View } from '@slack/web-api'; -import { HOMER_GIT_URL, MOES_TAVERN_CHANNEL_ID } from '@/constants'; +import { HOMER_GIT_URL, SLACK_SUPPORT_CHANNEL_ID } from '@/constants'; import type { SlackUser } from '@/core/typings/SlackUser'; export async function buildAppHomeView(user: SlackUser): Promise { @@ -15,7 +15,7 @@ export async function buildAppHomeView(user: SlackUser): Promise { text: `\ Hello *${firstName}*, I'm *Homer*, the Slack Gitlab master! -If you want to take a :beer: with me, don't hesitate to join <#${MOES_TAVERN_CHANNEL_ID}>. +If you want to take a :beer: with me, don't hesitate to join <#${SLACK_SUPPORT_CHANNEL_ID}>. If you want to better know me, here are some useful links: