Skip to content

Commit b58c3c6

Browse files
tphoneyactions-user
authored andcommitted
Fix blast radius numbers in the get-change report (#1523)
GitOrigin-RevId: fb9a3978ace7360bf25b0bd491e145976cab093b
1 parent e3434ae commit b58c3c6

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

sdp-go/util.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ func RenderItemDiff(gun string, before, after map[string]any, changeData, rawDat
161161
k := fmt.Sprintf("%v.%v", gun, key)
162162
v := attrs[k]
163163
slices.Sort(v)
164+
v = slices.Compact(v)
165+
for i, val := range v {
166+
val = strings.ReplaceAll(val, "\n", " ")
167+
val = strings.ReplaceAll(val, "\t", " ")
168+
if len(val) > 100 {
169+
val = val[:100]
170+
}
171+
v[i] = val
172+
}
164173

165174
if len(v) > 0 {
166175
para = append(para, fmt.Sprintf("# → 🔁 This attribute has changed %d times in the last 30 days.\n# The previous values were %v.", len(v), v))

sdp-go/util_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,36 @@ func TestItemDiffParagraphRendering(t *testing.T) {
175175
},
176176
ExpectedDiffParagraph: "",
177177
},
178+
{
179+
Name: "with stats, previous values truncated to 100 characters",
180+
Before: map[string]any{
181+
"name": map[string]any{
182+
"first": "test",
183+
"last": "user",
184+
},
185+
},
186+
After: map[string]any{
187+
"name": map[string]any{
188+
"first": "test",
189+
"last": "updated",
190+
},
191+
},
192+
ChangeRollups: []RoutineRollup{
193+
{
194+
Gun: "testGun",
195+
Attr: "name.last",
196+
Value: "user",
197+
},
198+
},
199+
RawRollups: []RoutineRollup{
200+
{
201+
Gun: "testGun",
202+
Attr: "name.last",
203+
Value: "123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.AAAAAA",
204+
},
205+
},
206+
ExpectedDiffParagraph: "- name.last: user\n+ name.last: updated\n# → 🔁 This attribute has changed 1 times in the last 30 days.\n# The previous values were [123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.].",
207+
},
178208
}
179209

180210
for _, test := range tests {

0 commit comments

Comments
 (0)