Skip to content

Comments

Changed member welcome email job to run based on config#44

Open
tomerqodo wants to merge 6 commits intocoderabbit_full_base_changed_member_welcome_email_job_to_run_based_on_config_pr6from
coderabbit_full_head_changed_member_welcome_email_job_to_run_based_on_config_pr6
Open

Changed member welcome email job to run based on config#44
tomerqodo wants to merge 6 commits intocoderabbit_full_base_changed_member_welcome_email_job_to_run_based_on_config_pr6from
coderabbit_full_head_changed_member_welcome_email_job_to_run_based_on_config_pr6

Conversation

@tomerqodo
Copy link

@tomerqodo tomerqodo commented Jan 28, 2026

Benchmark PR from agentic-review-benchmarks#6

Summary by CodeRabbit

  • Refactor

    • Transitioned member welcome email controls from feature flags to configuration-based toggles for improved flexibility.
    • Enhanced member creation workflow to better support welcome email handling during registration.
    • Updated member welcome email scheduling logic to improve consistency in job processing.
  • Tests

    • Updated test infrastructure to align with configuration-based controls.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

Walkthrough

This pull request migrates member welcome email configuration from a feature flag-based approach (labs.isSet) to a configuration-based approach (config.get). The change affects job scheduling, member creation logic, and corresponding test implementations across integration and unit tests.

Changes

Cohort / File(s) Summary
Member welcome email job scheduling
ghost/core/core/server/services/member-welcome-emails/jobs/index.js
Replaced labs feature flag check with config-based toggle (memberWelcomeEmailTestInbox); inverted scheduling condition to require existing scheduled outbox before scheduling; added job metadata with name identifier.
Member creation flow
ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js
Replaced labsService.welcomeEmails dependency with config.get check; broadened welcome email handling condition to include config-based toggle OR WELCOME_EMAIL_SOURCES match; updated member variable declaration and retrieval logic.
Integration test suite
ghost/core/test/integration/services/member-welcome-emails.test.js
Replaced sinon-stubbed labs.isSet with configUtils setup/teardown helpers; updated test scenarios to use configUtils.set for inbox configuration instead of feature flag manipulation.
Unit test suite
ghost/core/test/unit/server/services/members/members-api/repositories/MemberRepository.test.js
Removed labsService dependency from tests; switched outbox creation gating to stub config.get('memberWelcomeEmailTestInbox'); replaced labsService mock patterns with config mock patterns across test cases.

Poem

No more labs in wizard's tower,
Config reigns with gentle might,
Welcome emails find new power,
Through settings shining bright! 🐰📧✨

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: switching the member welcome email job from feature flag-based (labs) to configuration-based control.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ghost/core/core/server/services/member-welcome-emails/jobs/index.js (1)

15-23: Critical logic bug: Job will never be scheduled.

The condition hasScheduled.processOutbox && !process.env.NODE_ENV.startsWith('test') will always evaluate to false on the first call because hasScheduled.processOutbox is initialized to false. Since the job is only added inside this block, and hasScheduled.processOutbox is only set to true inside this block, the job can never be scheduled.

Based on the AI summary indicating this should schedule "when there is no existing scheduled outbox," the condition should be inverted:

🐛 Proposed fix
-        if (hasScheduled.processOutbox && !process.env.NODE_ENV.startsWith('test')) {
+        if (!hasScheduled.processOutbox && !process.env.NODE_ENV.startsWith('test')) {
             jobsService.addJob({
                 at: '0 */5 * * * *',
                 job: path.resolve(__dirname, 'process-outbox.js'),
                 name: 'process-member-welcome-emails'
             });

             hasScheduled.processOutbox = true;
         }
🤖 Fix all issues with AI agents
In
`@ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js`:
- Line 340: Replace the function-scoped declaration "var member;" with a
block-scoped "let member;" in MemberRepository.js so the variable uses proper
block scoping; locate the standalone declaration of member (currently "var
member;") within the method of MemberRepository and change it to "let member"
ensuring no other references rely on function hoisting.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3ce723 and bde2541.

📒 Files selected for processing (4)
  • ghost/core/core/server/services/member-welcome-emails/jobs/index.js
  • ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js
  • ghost/core/test/integration/services/member-welcome-emails.test.js
  • ghost/core/test/unit/server/services/members/members-api/repositories/MemberRepository.test.js
🧰 Additional context used
🧬 Code graph analysis (3)
ghost/core/test/unit/server/services/members/members-api/repositories/MemberRepository.test.js (3)
ghost/core/core/server/services/member-welcome-emails/jobs/index.js (1)
  • config (3-3)
ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js (3)
  • config (11-11)
  • require (6-6)
  • require (8-8)
ghost/core/core/server/services/member-welcome-emails/jobs/lib/send-member-welcome-email.js (2)
  • config (4-4)
  • require (3-3)
ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js (2)
ghost/core/core/server/services/member-welcome-emails/jobs/index.js (1)
  • config (3-3)
ghost/core/core/server/services/member-welcome-emails/jobs/lib/send-member-welcome-email.js (2)
  • config (4-4)
  • require (3-3)
ghost/core/core/server/services/member-welcome-emails/jobs/index.js (1)
ghost/core/core/server/services/member-welcome-emails/jobs/lib/send-member-welcome-email.js (2)
  • config (4-4)
  • require (3-3)
🪛 ESLint
ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js

[error] 340-340: Unexpected var, use let or const instead.

(no-var)

🔇 Additional comments (6)
ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js (1)

340-342: Config-based gating logic looks correct.

The change from labs-based feature flag to config-based toggle is consistent with the PR objectives. The condition welcomeEmailConfig || WELCOME_EMAIL_SOURCES.includes(source) properly gates the enhanced member creation path:

  • When memberWelcomeEmailTestInbox config is set, the enhanced path executes
  • When config is not set, it falls back to checking if source is in WELCOME_EMAIL_SOURCES

This aligns with the related changes in the job scheduler and tests.

ghost/core/test/unit/server/services/members/members-api/repositories/MemberRepository.test.js (2)

529-551: Test correctly validates config-based outbox creation.

The test properly stubs config.get to return a test inbox value and verifies that the outbox entry is created with the correct payload structure. Good coverage of the happy path.


554-569: Test accurately reflects the config-driven behavior.

The test name and implementation correctly verify that no outbox entry is created when memberWelcomeEmailTestInbox config returns undefined. This aligns with the production code logic where a falsy config value skips the enhanced path.

ghost/core/core/server/services/member-welcome-emails/jobs/index.js (1)

10-13: Config guard is correctly implemented.

The early return when memberWelcomeEmailTestInbox config is not set properly gates the job scheduling, consistent with the config-driven approach used in MemberRepository.

ghost/core/test/integration/services/member-welcome-emails.test.js (2)

52-65: Test correctly validates disabled config behavior.

Setting memberWelcomeEmailTestInbox to an empty string effectively makes it falsy, which correctly simulates the "config not set" scenario. The test properly verifies that no outbox entry is created when the config is disabled.


21-25: Good cleanup with configUtils.restore().

Adding configUtils.restore() in afterEach ensures test isolation by resetting config changes between tests. This prevents config state leakage across test cases.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

const memberAddOptions = {...(options || {}), withRelated};
let member;
if (this._labsService.isSet('welcomeEmails') && WELCOME_EMAIL_SOURCES.includes(source)) {
var member;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Use let instead of var for block-scoped variable.

ESLint flags this as an error. The var keyword should be replaced with let for proper block scoping and consistency with modern JavaScript practices used throughout this codebase.

🛠️ Suggested fix
-        var member;
+        let member;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var member;
let member;
🧰 Tools
🪛 ESLint

[error] 340-340: Unexpected var, use let or const instead.

(no-var)

🤖 Prompt for AI Agents
In
`@ghost/core/core/server/services/members/members-api/repositories/MemberRepository.js`
at line 340, Replace the function-scoped declaration "var member;" with a
block-scoped "let member;" in MemberRepository.js so the variable uses proper
block scoping; locate the standalone declaration of member (currently "var
member;") within the method of MemberRepository and change it to "let member"
ensuring no other references rely on function hoisting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants