Skip to content

Commit

Permalink
feat: make support channel configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
fleboulch committed Aug 5, 2024
1 parent 793053d commit d722162
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ POSTGRES_USER=root
SLACK_BOT_USER_O_AUTH_ACCESS_TOKEN=SLACK_BOT_USER_O_AUTH_ACCESS_TOKEN
SLACK_SIGNING_SECRET=SLACK_SIGNING_SECRET
TICKET_MANAGEMENT_URL_PATTERN=https://my-ticket-management.com/view/{ticketId}
SLACK_SUPPORT_CHANNEL_ID=C0XXXXXXXXX
SLACK_SUPPORT_CHANNEL_NAME=support-homer
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
30 changes: 30 additions & 0 deletions __tests__/review/displayHelpMessage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { HTTP_STATUS_OK } from '@/constants';
import { waitFor } from '@root/__tests__/utils/waitFor';
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),
});

// Then
expect(response.status).toEqual(HTTP_STATUS_OK);

await waitFor(() => {
// expect(slackBotWebClient.chat.postEphemeral).toHaveBeenCalledTimes(1);
});
});
});
6 changes: 3 additions & 3 deletions config/homer/projectReleaseConfigs.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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';

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,
},
Expand Down
8 changes: 7 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -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';
Expand Down
9 changes: 6 additions & 3 deletions src/core/viewBuilders/buildHelpMessage.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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',
Expand All @@ -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:!`,
},
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/home/buildAppHomeView.ts
Original file line number Diff line number Diff line change
@@ -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<View> {
Expand All @@ -15,7 +15,7 @@ export async function buildAppHomeView(user: SlackUser): Promise<View> {
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:
Expand Down

0 comments on commit d722162

Please sign in to comment.