Skip to content

Commit 63c3b56

Browse files
committed
Parsed report
Signed-off-by: pranav-zededa <[email protected]>
1 parent d973d32 commit 63c3b56

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

diff/diff.go

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func Manifests(oldIndex, newIndex map[string]*manifest.MappingResult, options *O
8181
}
8282

8383
// ManifestsDiffWithReport diff on manifests
84-
func ManifestsDiffWithReport(oldIndex, newIndex map[string]*manifest.MappingResult, options *Options, to io.Writer) Report {
84+
func ManifestsDiffWithReport(oldIndex, newIndex map[string]*manifest.MappingResult, options *Options, to io.Writer) ParsedReport {
8585
report := Report{}
8686
report.setupReportFormat(options.OutputFormat)
8787
var possiblyRemoved []string
@@ -124,26 +124,54 @@ func ManifestsDiffWithReport(oldIndex, newIndex map[string]*manifest.MappingResu
124124
}
125125

126126
report.print(to)
127-
report = filterReportsWithNonZeroDelta(report)
128-
return report
127+
parsedReport := filterReportsWithNonZeroDelta(report)
128+
return parsedReport
129129
}
130130

131-
func filterReportsWithNonZeroDelta(report Report) Report {
132-
var filteredEntries []ReportEntry
131+
func filterReportsWithNonZeroDelta(report Report) ParsedReport {
132+
var parsedEntries []ParsedEntry
133133
for _, entry := range report.entries {
134-
var filteredDiffs []difflib.DiffRecord
134+
var parsedDiffs []ParsedDiff
135135
for _, diff := range entry.diffs {
136136
if diff.Delta != 0 {
137-
filteredDiffs = append(filteredDiffs, diff)
137+
parsedDiffs = append(parsedDiffs, ParsedDiff{
138+
Payload: diff.Payload,
139+
Delta: int(diff.Delta),
140+
})
138141
}
139142
}
140-
if len(filteredDiffs) > 0 {
141-
entry.diffs = filteredDiffs
142-
filteredEntries = append(filteredEntries, entry)
143-
}
143+
parsedEntries = append(parsedEntries, ParsedEntry{
144+
Key: entry.key,
145+
Kind: entry.kind,
146+
Context: entry.context,
147+
Diffs: parsedDiffs,
148+
ChangeType: entry.changeType,
149+
})
144150
}
145-
report.entries = filteredEntries
146-
return report
151+
152+
return ParsedReport{Entries: parsedEntries}
153+
154+
}
155+
156+
// ParsedReport represents the parsed and organized report
157+
type ParsedReport struct {
158+
Entries []ParsedEntry `json:"entries"`
159+
}
160+
161+
// ParsedEntry represents a single entry in the parsed report
162+
type ParsedEntry struct {
163+
Key string `json:"key"`
164+
ReleaseName string `json:"releaseName"`
165+
Kind string `json:"kind"`
166+
Context int `json:"context"`
167+
Diffs []ParsedDiff `json:"diffs"`
168+
ChangeType string `json:"changeType"`
169+
}
170+
171+
// ParsedDiff represents a single diff in a parsed entry
172+
type ParsedDiff struct {
173+
Payload string `json:"payload"`
174+
Delta int `json:"delta"`
147175
}
148176

149177
func doSuppress(report Report, suppressedOutputLineRegex []string) (Report, error) {

0 commit comments

Comments
 (0)