Comments (13)
Build it into danger-kotlin
from kotlin.
I have created a little workaround by reading it through git
shell command
data class GitStats(val additions: Int, val deletions: Int)
fun GitLab.gitStats(): GitStats {
val diffRefs = mergeRequest.diffRefs
val commandOutput = ProcessBuilder("bash", "-c", "git diff --numstat ${diffRefs.startSha} ${diffRefs.headSha}")
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start().apply { waitFor(60, TimeUnit.MINUTES) }
.inputStream.bufferedReader().readText()
val pairs = commandOutput.lines()
.filter { it.isNotEmpty() }
.map { line ->
val parts = line.split("\\s+".toRegex())
parts[0].toInt() to parts[1].toInt()
}
val additions = pairs.fold(0) { acc, (addition, _) -> acc + addition }
val deletions = pairs.fold(0) { acc, (_, deletion) -> acc + deletion }
return GitStats(additions, deletions)
}
but it's not ideal of course :)
from kotlin.
Interesting workaround, let me to investigate!! if you are lucky i will find a solution shortly
from kotlin.
I have actually find out that danger js has it in their api - https://github.com/danger/danger-js/blob/b615ca41dffa0446c1651300c5d2731ff5988229/source/platforms/git/gitJSONToGitDSL.ts#L158 so maybe it could be easily read?
from kotlin.
good shout!! i'm on it!!
from kotlin.
I think with the current infrastructure that is the actual solution.
Danger-Kotlin doesn’t have a gitlab client, then if is the number of added/removed lines is not in the json we get from Danger-js, git looks the best way to get it.
But we added a danger utils exec to execute calls #98
Then we can release a new version and you can use that one instead, that could help to make the code more readable.
We could also have a function on git to get the added removed lines, but it would have an implementation really similar to the one you wrote.
from kotlin.
@f-meloni I'm probably a little bit lost now :\
Gitlab does not provide this info in their api. But danger-js does. And from my understanding of how danger-kotlin works, it's mainly a wrapper over danger-js. So if danger-js has this, it could be added to the Git
class introduced in danger-kotlin, right?
Or am I missing something?
from kotlin.
yeah that's the problem, we do not have direct access to the api.
Basically what we do is:
- get the JSON from danger js (an example can be found here https://github.com/danger/kotlin/blob/master/danger-kotlin-library/src/test/resources/gitlabDangerJSON.json)
danger js internally has other stuff, to do what you would like to have, we need danger-js to handle that and put everything in that Json. then we can read that.. but i don't know the feasibility right now..
we can keep in mind. but right now, your workaround is not a bad solution.. maybe can just use utils with something like:
data class GitStats(val additions: Int, val deletions: Int)
val GitLab.stats: GitStats
get() {
Utils().exec("git diff --numstat ${mergeRequest.diffRefs.startSha} ${mergeRequest.diffRefs.headSha}").let { output ->
val pairs = output.lines().filter { it.isNotEmpty() }
.map { line ->
val parts = line.split("\\s+".toRegex())
parts[0].toInt() to parts[1].toInt()
}
val additions = pairs.fold(0) { acc, (addition, _) -> acc + addition }
val deletions = pairs.fold(0) { acc, (_, deletion) -> acc + deletion }
return GitStats(additions, deletions)
}
}
from kotlin.
Danger Kotlin is a not exactly a wrapper over danger-js, they have only one “touch” point, that is the DSL danger-Kotlin receives from danger js (and then Danger Kotlin sends back another json).
Basically danger js handles getting and posting data on the PRs/MRs is not a continuous communication.
Everything else Danger-Kotlin has is built in
from kotlin.
aha! OK guys, now I understand it better :) I am planning to create a plugin with some common stuff that we will use for Merge requests at our company so I can put the extension there and it will be ok :) Thanks again! I love your work and I look forward when I move from danger in ruby to the danger in kotlin since kotlin is my day to day language. So see you soon with another question :D We can close this now I suppose :)
from kotlin.
and do not forget to think about us!!! and please feel free to fork our repo, and maybe contribute with interesting stuff!!
from kotlin.
Yeah, just to plus one this general thread as being the way to think about building Danger language implementations
Danger JS gets the same dumb JSON object as Danger Kotlin and then extends the JSON with it's own APIs - this API in particular is expensive in Danger JS and isn't done by default but it's up to languages to decide whether this should be built-in or not 👍
from kotlin.
Ok so I've tried to extract this to a plugin and I've hit a roadblock right from the beginning because I can't access GitLab
class in the plugin, looks like it's not provided through systems.danger:danger-kotlin-sdk:1.1
artifact. I can of course make my method for computing GitStats more abstract without direct dependency to a GitLab
class but I can imagine that in the future I would like to have access there. What do you suggest?
from kotlin.
Related Issues (20)
- Run on custom inhouse CI HOT 1
- MissingFieldException error in BitBucketServerReviewer HOT 3
- NullPointerException bitBucketServer HOT 7
- Alternative install for macOS HOT 5
- JsonDecodingException on approvals_before_merge
- Cannot install Kotlin Danger neither from git clone or ssh HOT 6
- Improve debugging capabilities HOT 1
- Consider editing repository setings to remove "Packages" section HOT 1
- Could not find a DangerFile HOT 3
- Kotlinc not found HOT 15
- New release date question HOT 1
- Danger Kotlin API Documentation
- Upgrade to newer JDK HOT 1
- Add label on a PR HOT 3
- Can't find Kotlin Compiler in Android Studio Preferences HOT 3
- MacOS Catalina default shell change to zsh causing issue in Bitrise HOT 2
- Autocomplete and Syntax Highlighting are not working on latest Android Studio HOT 3
- Could not find pull request information for private repo HOT 3
- Add binaries into release artifacts
- GitHubCommit: author and commiter can be empty objects HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlin.