Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve addition / modification / removal counts into the Report (and output in the header, or in brief, or via a new output) #393

Open
csabatuz-chess opened this issue Aug 8, 2024 · 0 comments

Comments

@csabatuz-chess
Copy link

csabatuz-chess commented Aug 8, 2024

Issue
Currently core.go is well aware of addition / modification / removal counts, during it's operation, but this information is getting lost in the Report, and not outputted in any of the output modes.

It's easier for me to demonstrate with a piece of code that extracts (something like) the information we're looking for

addition, modification, removal := 0, 0, 0
for _, diff := range report.Diffs {
  for _, detail := range diff.Details {
	if detail.Kind == ADDITION {
		addition += len(detail.To.Content)
	} else if detail.Kind == REMOVAL {
		removal += len(detail.From.Content)
	} else if detail.Kind == MODIFICATION {
		modification += 1
	}
  }
}

fmt.Println(fmt.Sprintf("Changes: %d additions, %d modifications, %d removals", addition, modification, removal))

THis piece of code is nesting the additions and removals into a single Diff, so currently if we add 5 new documents, we get back one change detected when in fact 5 additions occurred:
https://github.com/homeport/dyff/blob/main/pkg/dyff/core.go#L747-L769

Context
We are using dyff as part of a CI action to compare rendered K8S manifests before/after PR, and the produced diff is by far the best among all the tools we tried. So we are very committed to sticking with dyff.

The diff itself is linked to in GH action output, which is great but we'd like to add a summary in the comment message where we link to GH action run logs.

But currently it's impossible to extract this information, and we'd like to avoid forking if possible.

If these additions / modifications / removals counts could be preserved, and printed in some way, we could use text processing to parse and make it into the format we need. But right now modification of the code is necessary.

Footnote

  • Big thanks for creating this tool. There's basically no alternatives to it when it comes to offline comparing K8S manifests.
  • I can contribute PR as well, but not sure what's the best way to preserve this information and how to make sure it's accurate, some more reading of the code will be necessary for that, but I wanted to create the issue for discussion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant