Make delivery summary posting optional per program#498
Conversation
program Programs may have different preferences about whether campaign delivery summaries should be posted to their Slack channel - Added `send_delivery_summaries` boolean field to programs (defaults false) - Conditionally render the checkbox in the form only when a Slack channel is selected, preventing accidental configuration without a channel - Updated CampaignSummaryPoster to check this flag before posting
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds a per-program boolean ChangesDelivery Summaries Feature Flag
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
channel configured. This is the existing behaviour.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/bike_brigade/campaign_summary_poster.ex`:
- Around line 69-77: Add a defensive clause to do_post_summary/3 so non-true
values for the send_delivery_summaries flag (nil, false, or any other unexpected
value) don't cause a FunctionClauseError; for example add a clause like defp
do_post_summary(campaign, _channel_id, flag) when flag != true do
Logger.info("Skipping campaign #{campaign.id}: delivery summaries not enabled
for program (flag: #{inspect(flag)})") end to catch nil/false/invalid flag
values before the do_post_summary(campaign, channel_id, true) clause.
In
`@priv/repo/migrations/20260512195708_add_send_delivery_summaries_to_programs.exs`:
- Line 6: The migration currently adds the column send_delivery_summaries with a
default but allows NULLs; update the migration's change function so the add
statement for :send_delivery_summaries uses null: false (e.g. add
:send_delivery_summaries, :boolean, default: false, null: false) to enforce a
non-null boolean at the DB level; ensure the migration's down/rollback behavior
(or change callback) remains correct after this change.
In
`@priv/repo/migrations/20260519000001_enable_send_delivery_summaries_for_programs_with_slack_channel.exs`:
- Around line 8-12: The migration currently references the schema module
BikeBrigade.Delivery.Program which can break replay; change the query to use the
table name string instead (e.g., from(p in "programs", update: [set:
[send_delivery_summaries: true]], where: not is_nil(p.slack_channel_id))) and
keep the Repo.update_all call, so the migration uses raw table-based Ecto
queries rather than the application schema module.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0231233d-f6ef-4f85-bbc2-b8c75047e0ec
📒 Files selected for processing (5)
lib/bike_brigade/campaign_summary_poster.exlib/bike_brigade/delivery/program.exlib/bike_brigade_web/live/program_live/form_component.html.heexpriv/repo/migrations/20260512195708_add_send_delivery_summaries_to_programs.exspriv/repo/migrations/20260519000001_enable_send_delivery_summaries_for_programs_with_slack_channel.exs
There was a problem hiding this comment.
3 issues found across 5 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="priv/repo/migrations/20260519000001_enable_send_delivery_summaries_for_programs_with_slack_channel.exs">
<violation number="1" location="priv/repo/migrations/20260519000001_enable_send_delivery_summaries_for_programs_with_slack_channel.exs:8">
P2: Using application schema modules (`BikeBrigade.Delivery.Program`) in migrations can break replay on new environments if the schema later changes. Use raw SQL via `execute/1` instead to keep the migration self-contained.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| alias BikeBrigade.Repo | ||
|
|
||
| def up do | ||
| from(prog in BikeBrigade.Delivery.Program, |
There was a problem hiding this comment.
P2: Using application schema modules (BikeBrigade.Delivery.Program) in migrations can break replay on new environments if the schema later changes. Use raw SQL via execute/1 instead to keep the migration self-contained.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At priv/repo/migrations/20260519000001_enable_send_delivery_summaries_for_programs_with_slack_channel.exs, line 8:
<comment>Using application schema modules (`BikeBrigade.Delivery.Program`) in migrations can break replay on new environments if the schema later changes. Use raw SQL via `execute/1` instead to keep the migration self-contained.</comment>
<file context>
@@ -0,0 +1,16 @@
+ alias BikeBrigade.Repo
+
+ def up do
+ from(prog in BikeBrigade.Delivery.Program,
+ update: [set: [send_delivery_summaries: true]],
+ where: not is_nil(prog.slack_channel_id)
</file context>
mveytsman
left a comment
There was a problem hiding this comment.
the column should be nil: false, you'll need a third miogration to set null false, this addresses the code rabbit errors
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
- Use guard clause in pattern matching to handle all falsy values - Add NOT NULL constraint to send_delivery_summaries column for data integrity
Summary
Make delivery summary posting optional per program, allowing programs to control whether campaign
delivery summaries are posted to their configured Slack channel.
Problem
Previously, campaign delivery summaries were automatically posted to Slack whenever a program had a Slack channel configured. This didn't account for programs that may not want this automated notification,
creating unnecessary Slack traffic for some teams.
Solution
send_delivery_summariesboolean field to programs (defaults tofalse)CampaignSummaryPosterto check this flag before posting summariesChanges
Backend:
send_delivery_summariescolumn toprogramstableProgramschema to include the new fieldCampaignSummaryPoster.post_summary_for_campaign/1to check the flag before postingFrontend:
:ifdirective to prevent showing the option when channel is not configuredNote
Programs that want delivery summaries need to explicitly enable the checkbox.
Checklist before requesting a review
about this update in the description above.
Opt-in delivery summaries: programs control whether campaign delivery summaries are posted to Slack channel.
Summary by cubic
Make Slack delivery summaries opt-in per program so teams control whether summaries are posted. Default is off; existing programs with a Slack channel stay enabled, with stricter checks for safety.
New Features
send_delivery_summarieson programs (defaultfalse).CampaignSummaryPosterrespects the flag; skips and logs info when disabled or no channel (no Slack error notification when channel is missing).true(treats all other values as disabled).Migration
send_delivery_summariesfor programs that already have a Slack channel.send_delivery_summariesfor data integrity.Written for commit 461da10. Summary will update on new commits. Review in cubic
Summary by CodeRabbit
New Features
Chores