Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make emails configurable #12

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_DOMAINS=my-domain.com,ext.my-domain.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_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:

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_DOMAINS = getEnvVariable('EMAIL_DOMAINS');

// 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_DOMAINS.split(',').map(
(emailDomain) => `${username}@${emailDomain}`
);
return fetchSlackUserFromEmails(emails);
}

export async function fetchSlackUserFromId(
Expand Down
Loading