Skip to content

Commit

Permalink
Add fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
fleboulch committed May 21, 2024
1 parent a97e47b commit 002ad19
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 0 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 8 additions & 2 deletions src/core/services/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 12 additions & 0 deletions src/core/utils/getEnvVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 002ad19

Please sign in to comment.