From 3e88410d35cdd18fdc48f9e27a071362c812d136 Mon Sep 17 00:00:00 2001 From: Kiran Muddukrishna Date: Sat, 4 Jul 2026 16:21:36 +1000 Subject: [PATCH] feat(github): show a single multi-env plan change inline Only collapse a multi-environment plan section's DDL behind a details block when it has more than one change. A single statement (or a lone VSchema diff) is small enough to read without a click, so render it inline while keeping the summary below. --- pkg/webhook/plan_test.go | 37 +++++++++++++++++++++++++++++++++-- pkg/webhook/templates/plan.go | 11 ++++++++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/pkg/webhook/plan_test.go b/pkg/webhook/plan_test.go index 4cec6178..79f47b04 100644 --- a/pkg/webhook/plan_test.go +++ b/pkg/webhook/plan_test.go @@ -716,8 +716,10 @@ func TestRenderMultiEnvPlanComment_CollapsesDDL(t *testing.T) { "the plan summary should stay outside (below) the collapsed DDL") } -// A single statement uses the singular "statement" in the collapse summary. -func TestRenderMultiEnvPlanComment_CollapseSummarySingular(t *testing.T) { +// A multi-environment plan with a single change is small enough to show inline, +// so its DDL is rendered directly instead of behind a
block while the +// plan summary still appears below. +func TestRenderMultiEnvPlanComment_SingleChangeInline(t *testing.T) { changes := []templates.KeyspaceChangeData{{ Keyspace: "testdb", Statements: []string{"ALTER TABLE `orders` ADD COLUMN `x` INT"}, @@ -735,6 +737,37 @@ func TestRenderMultiEnvPlanComment_CollapseSummarySingular(t *testing.T) { rendered := templates.RenderMultiEnvPlanComment(data) + assert.NotContains(t, rendered, "
", "a single change renders inline, not collapsed") + assert.Contains(t, rendered, "```sql") + assert.Contains(t, rendered, "ALTER TABLE `orders` ADD COLUMN `x` int") + // The plan summary still appears (below the inline DDL). + assert.Contains(t, rendered, "📋 **Plan**") +} + +// When a plan has more than one change overall — here a single DDL statement +// alongside a VSchema update — the DDL still collapses, and the summary uses the +// singular "statement" for the one statement it contains. +func TestRenderMultiEnvPlanComment_CollapseSummarySingular(t *testing.T) { + changes := []templates.KeyspaceChangeData{{ + Keyspace: "testks", + Statements: []string{"ALTER TABLE `orders` ADD COLUMN `x` INT"}, + VSchemaChanged: true, + VSchemaDiff: "+ vindex added", + }} + data := templates.MultiEnvPlanCommentData{ + Database: "testks", + IsMySQL: false, + DatabaseType: "PlanetScale", + Environments: []string{"staging", "production"}, + Plans: map[string]*templates.PlanCommentData{ + "staging": {Database: "testks", Environment: "staging", IsMySQL: false, DatabaseType: "PlanetScale", Changes: changes}, + "production": {Database: "testks", Environment: "production", IsMySQL: false, DatabaseType: "PlanetScale", Changes: changes}, + }, + Errors: map[string]string{}, + } + + rendered := templates.RenderMultiEnvPlanComment(data) + assert.Contains(t, rendered, "Show SQL (1 statement)") } diff --git a/pkg/webhook/templates/plan.go b/pkg/webhook/templates/plan.go index 0ab04d6a..164330a1 100644 --- a/pkg/webhook/templates/plan.go +++ b/pkg/webhook/templates/plan.go @@ -815,9 +815,14 @@ func writeEnvironmentPlanSection(sb *strings.Builder, plan *PlanCommentData) { return } - // Detailed changes, collapsed so the DDL doesn't dominate the comment while - // the unsafe/lint warnings and summary below stay visible at a glance. - writeCollapsibleKeyspaceChanges(sb, *plan, totalStatements) + // Detailed changes. A single change is small enough to show inline; more + // than one is collapsed so the DDL doesn't dominate the comment while the + // unsafe/lint warnings and summary below stay visible at a glance. + if totalChanges == 1 { + writeKeyspaceChanges(sb, *plan) + } else { + writeCollapsibleKeyspaceChanges(sb, *plan, totalStatements) + } // Unsafe changes warning if plan.HasUnsafeChanges && len(plan.UnsafeChanges) > 0 {