MCPcopy Create free account
hub / github.com/conforma/cli / FormatPolicyDifferences

Function FormatPolicyDifferences

internal/validate/vsa/validator.go:219–247  ·  view source on GitHub ↗

FormatPolicyDifferences formats policy differences using unified diff format

(differences []equivalence.PolicyDifference)

Source from the content-addressed store, hash-verified

217
218// FormatPolicyDifferences formats policy differences using unified diff format
219func FormatPolicyDifferences(differences []equivalence.PolicyDifference) string {
220 if len(differences) == 0 {
221 return "VSA policy does not match supplied policy (no specific differences identified)"
222 }
223
224 // Count different types of changes for the header
225 added, removed, changed := 0, 0, 0
226 for _, diff := range differences {
227 switch diff.Kind {
228 case equivalence.DiffAdded:
229 added++
230 case equivalence.DiffRemoved:
231 removed++
232 case equivalence.DiffChanged:
233 changed++
234 }
235 }
236
237 var sb strings.Builder
238 sb.WriteString(fmt.Sprintf("❌ Policy mismatch detected — %d added, %d removed, %d changed; %d differences\n",
239 added, removed, changed, len(differences)))
240
241 // Generate unified diff output
242 checker := &equivalence.EquivalenceChecker{}
243 unifiedDiff := checker.GenerateUnifiedDiffOutputWithLabels(differences, "VSA Policy", "Release Policy")
244 sb.WriteString(unifiedDiff)
245
246 return sb.String()
247}
248
249// ParseEffectiveTime parses the effective time string
250func ParseEffectiveTime(effectiveTime string) (time.Time, error) {

Callers 2

Calls 2

StringMethod · 0.45

Tested by 1