diff --git a/.env.test b/.env.test index fd8b358..fc44bcc 100644 --- a/.env.test +++ b/.env.test @@ -7,3 +7,4 @@ 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_DOMAINS=my-domain.com,ext.my-domain.com diff --git a/README.md b/README.md index ee4b1d0..13be23b 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,12 @@ Create a `.env` file containing the following variables: ![OAuth token](docs/assets/slack/oauth-token.png) +- `EMAIL_DOMAINS` + Email domains of your organization (separated by comma), + for instance `my-domain.com,ext.my-domain.com`. + Used to find Slack users from Gitlab username. + Note that this means your org has to use the same naming scheme for emails and gitlab username. + If you want Homer to connect to an **external PostgreSQL database**, you can set the following variables: diff --git a/src/core/services/slack.ts b/src/core/services/slack.ts index a7618d7..6787f5a 100644 --- a/src/core/services/slack.ts +++ b/src/core/services/slack.ts @@ -8,6 +8,7 @@ import { logger } from './logger'; const SLACK_BOT_USER_O_AUTH_ACCESS_TOKEN = getEnvVariable( 'SLACK_BOT_USER_O_AUTH_ACCESS_TOKEN' ); +const EMAIL_DOMAINS = getEnvVariable('EMAIL_DOMAINS'); // This client should be used for everything else. export const slackBotWebClient = new WebClient( @@ -94,10 +95,10 @@ export async function fetchSlackUserFromGitlabUser({ export async function fetchSlackUserFromGitlabUsername( username: string ): Promise { - return fetchSlackUserFromEmails([ - `${username}@manomano.com`, - `${username}@prt.manomano.com`, - ]); + const emails = EMAIL_DOMAINS.split(',').map( + (emailDomain) => `${username}@${emailDomain}` + ); + return fetchSlackUserFromEmails(emails); } export async function fetchSlackUserFromId(