Skip to content

Started inserting automation run when member signs up#28263

Merged
troyciesco merged 3 commits into
mainfrom
insert-automation-run-when-member-signs-up
Jun 3, 2026
Merged

Started inserting automation run when member signs up#28263
troyciesco merged 3 commits into
mainfrom
insert-automation-run-when-member-signs-up

Conversation

@EvanHahn
Copy link
Copy Markdown
Contributor

@EvanHahn EvanHahn commented May 30, 2026

towards https://linear.app/ghost/issue/NY-1286
ref #28120

I recommend reviewing this with whitespace changes disabled.

When a member signs up, we should trigger an automation run and possibly insert a new row.

Nothing happens yet when these rows are inserted. That will be done in a future change.

This is development-only; triggering is a no-op in production.

I tested this by:

  • Adding automated tests.

  • Verified that the old member welcome email is still sent on member signup.

  • Creating this temporary endpoint and verifying that the results looked expected after member signup:

    router.get('/automations/database-dump', (_req, res) => {
        const db = getTemporaryFakeAutomationsDatabase();
        res.json({
            automation_runs: db.prepare('SELECT * FROM automation_runs').all(),
            automation_run_steps: db.prepare('SELECT * FROM automation_run_steps').all()
        });
    });

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2a28357a-b80e-4b14-afcb-ece4e1f1bae2

📥 Commits

Reviewing files that changed from the base of the PR and between 66fb886 and b257018.

📒 Files selected for processing (3)
  • ghost/core/core/server/services/automations/automations-api.ts
  • ghost/core/core/server/services/gifts/gift-service.ts
  • ghost/core/core/server/services/members/members-api/members-api.js
💤 Files with no reviewable changes (1)
  • ghost/core/core/server/services/gifts/gift-service.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • ghost/core/core/server/services/automations/automations-api.ts

Walkthrough

This PR adds a public automationsApi.trigger(options) entrypoint (event restricted to 'member_sign_up'), a repository-level trigger implementation that schedules automation runs/steps based on the first eligible action revision and action type (wait/send_email), ES-module and schema updates for the temporary fake automations DB, MemberRepository wiring to call the new trigger (while preserving the legacy welcome-email enqueue path), GiftService updates to use the new method for paid signups, and unit tests covering repository and integration behaviors.

Possibly related PRs

  • TryGhost/Ghost#28170: Both PRs tie into the StartAutomationsPollEvent flow: one dispatches the event after trigger, the other updates the poll handler.
  • TryGhost/Ghost#28243: Both PRs modify member-repository.test.js to exercise the automationsApi.trigger-based member-signup automation path.
  • TryGhost/Ghost#27872: Both PRs use the automations labs/feature flag to change welcome-email/automation behavior.

Suggested labels

ok to merge for me

Suggested reviewers

  • troyciesco
  • cmraible
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding logic to insert automation run records when a member signs up, which aligns with the file-level changes across automations-api, automations-repository, and member-repository.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose (triggering automation runs on member signup), scope (development-only, no-op in production), testing approach, and acknowledging that runtime effects will follow in future work.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch insert-automation-run-when-member-signs-up

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

coderabbitai[bot]

This comment was marked as resolved.

towards https://linear.app/ghost/issue/NY-1286

*I recommend reviewing this with whitespace changes disabled.*

When a member signs up, we should trigger an automation run and possibly
insert a new row.

Nothing happens yet when these rows are inserted--that will be done in a
future change.

This is development-only; triggering is a no-op in production.
@EvanHahn EvanHahn force-pushed the insert-automation-run-when-member-signs-up branch from 4289304 to 66fb886 Compare May 30, 2026 20:28
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Had to convert this to TypeScript so I could import it from another TypeScript file. (Alternatively, I could've added temporary-fake-database.d.ts, but I think that's strictly worse.

Comment thread ghost/core/core/server/services/automations/automations-api.ts
@EvanHahn EvanHahn requested a review from troyciesco May 30, 2026 20:29
Comment thread ghost/core/core/server/services/automations/automations-api.ts
}

function findFirstActionRevision(database: DatabaseSync, memberStatus: 'free' | 'paid'): NextActionRevisionRow | null {
const automationSlug: NonNullable<string> = MEMBER_WELCOME_EMAIL_SLUGS[memberStatus];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm...not necessarily something for this PR and I might be over thinking it, but given we talked about moving away from using the slug to identify the automation, I wonder if there's a different way we should do this? Would this involve adding the concept of a trigger node perhaps? (not that i want to overcomplicate it at this step, but could at least be worth thinking about how this should work without slugs since we have a fake db to tinker with)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, but I think this should be done separately. I don't want to build "proper" triggers prematurely, and I don't think this blocks us from doing so.

@EvanHahn EvanHahn requested a review from troyciesco June 3, 2026 13:40
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