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

Tip: Use diffparser for git DSL #304

Open
hubertgrzeskowiak opened this issue Mar 4, 2025 · 1 comment
Open

Tip: Use diffparser for git DSL #304

hubertgrzeskowiak opened this issue Mar 4, 2025 · 1 comment

Comments

@hubertgrzeskowiak
Copy link

I struggled with the raw diffs at first, even writing my own parsers, before I discovered a better way. I thought I'd share a good library that works perfectly with danger-kotlin: https://github.com/thombergs/diffparser

Usage example:

@file:Repository("https://jcenter.bintray.com")
@file:DependsOn("io.reflectoring.diffparser:diffparser:1.4")


danger(args) {
  val diff = UnifiedDiffParser().parse(git.diff!!.byteInputStream())
}

From that object, it's trivial to get changed files, lines added, removed, the different chunks etc. It's a small library, so autocompletion should be all the docs you need, really.

@hubertgrzeskowiak
Copy link
Author

Happy to add this to the README if you reckon it's useful enough, but I didn't want to add anything that may break.

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