@@ -36,6 +36,7 @@ import (
3636const (
3737 releasePlanHashPruneMinMapKeys = 4
3838 releasePlanHashPruneMinArrayItems = 4
39+ releasePlanDiffMaxDepth = 50
3940 releasePlanDiffChangeTypeOrder = "order_changed"
4041 releasePlanDiffDisplayApprovalSpec = "approval_spec"
4142 releasePlanDiffDisplayWorkflowSpec = "workflow_spec"
@@ -368,6 +369,10 @@ func extractReleasePlanSectionSnapshot(snapshot interface{}, sectionKey string)
368369}
369370
370371func diffReleasePlanValues (ctx releasePlanDiffContext , path string , left , right interface {}, entries * []* releasePlanRawDiffEntry ) {
372+ diffReleasePlanValuesWithDepth (ctx , path , 0 , left , right , entries )
373+ }
374+
375+ func diffReleasePlanValuesWithDepth (ctx releasePlanDiffContext , path string , depth int , left , right interface {}, entries * []* releasePlanRawDiffEntry ) {
371376 if shouldIgnoreReleasePlanDiffPath (path ) {
372377 return
373378 }
@@ -380,6 +385,15 @@ func diffReleasePlanValues(ctx releasePlanDiffContext, path string, left, right
380385 return
381386 }
382387
388+ if depth >= releasePlanDiffMaxDepth {
389+ * entries = append (* entries , & releasePlanRawDiffEntry {
390+ Path : path ,
391+ Before : left ,
392+ After : right ,
393+ })
394+ return
395+ }
396+
383397 leftMap , leftIsMap := left .(map [string ]interface {})
384398 rightMap , rightIsMap := right .(map [string ]interface {})
385399 if leftIsMap || rightIsMap {
@@ -397,15 +411,15 @@ func diffReleasePlanValues(ctx releasePlanDiffContext, path string, left, right
397411 sort .Strings (keys )
398412 for _ , key := range keys {
399413 nextPath := joinReleasePlanDiffPath (path , key )
400- diffReleasePlanValues (ctx , nextPath , leftMap [key ], rightMap [key ], entries )
414+ diffReleasePlanValuesWithDepth (ctx , nextPath , depth + 1 , leftMap [key ], rightMap [key ], entries )
401415 }
402416 return
403417 }
404418
405419 leftList , leftIsList := left .([]interface {})
406420 rightList , rightIsList := right .([]interface {})
407421 if leftIsList || rightIsList {
408- diffReleasePlanArray (ctx , path , leftList , rightList , entries )
422+ diffReleasePlanArray (ctx , path , depth , leftList , rightList , entries )
409423 return
410424 }
411425
@@ -460,17 +474,17 @@ func hashReleasePlanSubtree(value interface{}) (string, error) {
460474 return hex .EncodeToString (sum [:]), nil
461475}
462476
463- func diffReleasePlanArray (ctx releasePlanDiffContext , path string , left , right []interface {}, entries * []* releasePlanRawDiffEntry ) {
477+ func diffReleasePlanArray (ctx releasePlanDiffContext , path string , depth int , left , right []interface {}, entries * []* releasePlanRawDiffEntry ) {
464478 rule := matchReleasePlanArrayDiffRule (ctx , path )
465479 if rule == nil || rule .Strategy == releasePlanArrayDiffStrategyIndex {
466- diffReleasePlanArrayByIndex (ctx , path , left , right , entries )
480+ diffReleasePlanArrayByIndex (ctx , path , depth , left , right , entries )
467481 return
468482 }
469483
470484 leftMap , leftOrdered , leftMapped := buildReleasePlanArrayMap (left , rule .BuildKey )
471485 rightMap , rightOrdered , rightMapped := buildReleasePlanArrayMap (right , rule .BuildKey )
472486 if ! leftMapped || ! rightMapped {
473- diffReleasePlanArrayByIndex (ctx , path , left , right , entries )
487+ diffReleasePlanArrayByIndex (ctx , path , depth , left , right , entries )
474488 return
475489 }
476490
@@ -500,12 +514,12 @@ func diffReleasePlanArray(ctx releasePlanDiffContext, path string, left, right [
500514 continue
501515 }
502516 nextPath := fmt .Sprintf ("%s[%s]" , path , key )
503- diffReleasePlanValues (ctx , nextPath , leftMap [key ], rightMap [key ], entries )
517+ diffReleasePlanValuesWithDepth (ctx , nextPath , depth + 1 , leftMap [key ], rightMap [key ], entries )
504518 }
505519 return
506520 }
507521
508- diffReleasePlanArrayByIndex (ctx , path , left , right , entries )
522+ diffReleasePlanArrayByIndex (ctx , path , depth , left , right , entries )
509523}
510524
511525func shouldSkipReleasePlanWorkflowTaskPresenceChange (path string , left , right interface {}) bool {
@@ -516,7 +530,7 @@ func shouldSkipReleasePlanWorkflowTaskPresenceChange(path string, left, right in
516530 return normalizedPath == "spec.workflow.jobs" || strings .HasSuffix (normalizedPath , ".spec.workflow.jobs" )
517531}
518532
519- func diffReleasePlanArrayByIndex (ctx releasePlanDiffContext , path string , left , right []interface {}, entries * []* releasePlanRawDiffEntry ) {
533+ func diffReleasePlanArrayByIndex (ctx releasePlanDiffContext , path string , depth int , left , right []interface {}, entries * []* releasePlanRawDiffEntry ) {
520534 maxLen := len (left )
521535 if len (right ) > maxLen {
522536 maxLen = len (right )
@@ -530,7 +544,7 @@ func diffReleasePlanArrayByIndex(ctx releasePlanDiffContext, path string, left,
530544 if i < len (right ) {
531545 rightVal = right [i ]
532546 }
533- diffReleasePlanValues (ctx , nextPath , leftVal , rightVal , entries )
547+ diffReleasePlanValuesWithDepth (ctx , nextPath , depth + 1 , leftVal , rightVal , entries )
534548 }
535549}
536550
0 commit comments