Skip to content

Commit

Permalink
fix: make emails configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
fleboulch-hw authored and fleboulch committed May 17, 2024
1 parent b1ed5b7 commit a97e47b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -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_PATTERNS=@manomano.com,@prt.manomano.com
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ Create a `.env` file containing the following variables:

![OAuth token](docs/assets/slack/oauth-token.png)

- `EMAIL_PATTERNS`
Email patterns of your organization (separated by comma),
for instance `@my.org,@contractors.my.org`.
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:

Expand Down
9 changes: 5 additions & 4 deletions src/core/services/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_PATTERNS = getEnvVariable('EMAIL_PATTERNS');

// This client should be used for everything else.
export const slackBotWebClient = new WebClient(
Expand Down Expand Up @@ -94,10 +95,10 @@ export async function fetchSlackUserFromGitlabUser({
export async function fetchSlackUserFromGitlabUsername(
username: string
): Promise<SlackUser | undefined> {
return fetchSlackUserFromEmails([
`${username}@manomano.com`,
`${username}@prt.manomano.com`,
]);
const emails = EMAIL_PATTERNS.split(',').map(
(emailPattern) => `${username}${emailPattern}`
);
return fetchSlackUserFromEmails(emails);
}

export async function fetchSlackUserFromId(
Expand Down

0 comments on commit a97e47b

Please sign in to comment.