diff --git a/.env.test b/.env.test index 77234f4..fd8b358 100644 --- a/.env.test +++ b/.env.test @@ -7,4 +7,3 @@ 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 -EMAIL_PATTERNS=@manomano.com,@prt.manomano.com diff --git a/src/core/services/slack.ts b/src/core/services/slack.ts index 03f4fc9..1268bab 100644 --- a/src/core/services/slack.ts +++ b/src/core/services/slack.ts @@ -2,13 +2,19 @@ import { WebClient } from '@slack/web-api'; import fetch from 'node-fetch'; import type { GitlabUser } from '@/core/typings/GitlabUser'; import type { SlackUser } from '@/core/typings/SlackUser'; -import { getEnvVariable } from '@/core/utils/getEnvVariable'; +import { + getEnvVariable, + getEnvVariableOrDefault, +} from '@/core/utils/getEnvVariable'; import { logger } from './logger'; const SLACK_BOT_USER_O_AUTH_ACCESS_TOKEN = getEnvVariable( 'SLACK_BOT_USER_O_AUTH_ACCESS_TOKEN' ); -const EMAIL_PATTERNS = getEnvVariable('EMAIL_PATTERNS'); +const EMAIL_PATTERNS = getEnvVariableOrDefault( + 'EMAIL_PATTERNS', + '@manomano.com,@prt.manomano.com' +); // This client should be used for everything else. export const slackBotWebClient = new WebClient( diff --git a/src/core/utils/getEnvVariable.ts b/src/core/utils/getEnvVariable.ts index 6830c20..6202de8 100644 --- a/src/core/utils/getEnvVariable.ts +++ b/src/core/utils/getEnvVariable.ts @@ -6,3 +6,15 @@ export function getEnvVariable(name: string): string { } return variable; } + +export function getEnvVariableOrDefault( + name: string, + defaultValue: string +): string { + const variable = process.env[name]; + + if (variable === undefined) { + return defaultValue; + } + return variable; +}