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

Improve optional modules loading #1052

Merged
merged 4 commits into from
Feb 15, 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
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

All changes that impact users of this module are documented in this file, in the [Common Changelog](https://common-changelog.org) format with some additional specifications defined in the CONTRIBUTING file. This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## Unreleased [minor]

_Full changeset and discussions: [#1052](https://github.com/OpenTermsArchive/engine/pull/1052)._

> Development of this release was supported by the [French Ministry for Foreign Affairs](https://www.diplomatie.gouv.fr/fr/politique-etrangere-de-la-france/diplomatie-numerique/) through its ministerial [State Startups incubator](https://beta.gouv.fr/startups/open-terms-archive.html) under the aegis of the Ambassador for Digital Affairs.

### Changed

- **Breaking:** Base the loading of the Notifier module on the presence of required configuration, not on the environment; only define the `SENDINBLUE_API_KEY` environment variable if you want the Notifier to be loaded, avoid relying on `NODE_ENV=production`

## 0.35.0 - 2024-02-14

Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ export default async function track({ services, types, extractOnly, schedule })
return;
}

if (process.env.NODE_ENV === 'production') {
if (process.env.SENDINBLUE_API_KEY) {
archivist.attach(new Notifier(archivist.services));
} else {
logger.warn('Environment variable "SENDINBLUE_API_KEY" was not found; the Notifier module will be ignored');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In logs, aim for descriptions that explain the impact to the end user: “the Notifier module will be ignored” is not a clear way to understand the consequences of an action and to assess whether it can be the source of an unexpected behaviour 🙂

}

if (process.env.GITHUB_TOKEN) {
Expand All @@ -49,8 +51,10 @@ export default async function track({ services, types, extractOnly, schedule })
await reporter.initialize();
archivist.attach(reporter);
} else {
logger.warn('Configuration key "reporter.githubIssues.repositories.declarations" was not found; the Reporter module will be ignored\n');
logger.warn('Configuration key "reporter.githubIssues.repositories.declarations" was not found; the Reporter module will be ignored');
}
} else {
logger.warn('Environment variable "GITHUB_TOKEN" was not found; the Notifier module will be ignored');
}

if (!schedule) {
Expand Down
2 changes: 1 addition & 1 deletion src/logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const consoleTransport = new winston.transports.Console();

const transports = [consoleTransport];

if (config.get('logger.sendMailOnError')) {
if (process.env.SMTP_PASSWORD && config.get('logger.sendMailOnError')) {
const mailerOptions = {
to: config.get('logger.sendMailOnError.to'),
from: config.get('logger.sendMailOnError.from'),
Expand Down
Loading