Skip to content

Commit 771733f

Browse files
committed
Improve sample
1 parent f8d6efe commit 771733f

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

sample.main.kts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
11
@file:Repository("https://jitpack.io")
2-
@file:DependsOn("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.4")
2+
@file:DependsOn("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.9")
3+
4+
/*
5+
* Counts how many developers don't run tests on their local machine
6+
*/
37

48
import com.gabrielfeo.gradle.enterprise.api.*
9+
import kotlinx.coroutines.*
10+
import kotlinx.coroutines.flow.*
11+
import java.time.*
12+
13+
val oneMonthAgo = LocalDate.now()
14+
.minusMonths(1)
15+
.atStartOfDay()
16+
.toInstant(ZoneOffset.UTC)
17+
.toEpochMilli()
18+
19+
runBlocking {
20+
21+
// Filter builds from the API
22+
val buildsByUser = api.getGradleAttributesFlow(since = oneMonthAgo)
23+
.filter { "CI" !in it.tags }
24+
.toList()
25+
.groupBy { it.environment.username }
26+
check(buildsByUser.isNotEmpty()) { "No builds found!" }
27+
28+
// Count users
29+
val userCount = buildsByUser.size
30+
val userCountDoesntRunTestsLocally = buildsByUser.count { (_, userBuilds) ->
31+
userBuilds.none { build ->
32+
build.requestedTasks.any { task -> "test" in task.lowercase() }
33+
}
34+
}
35+
36+
// Present result
37+
val percent = "%.2f".format(userCountDoesntRunTestsLocally / userCount.toDouble() * 100)
38+
print("$percent% of developers don't run tests on their local machine")
39+
shutdown()
540

6-
val builds = api.getBuilds(since = 0, maxBuilds = 3).execute().body()!!
7-
builds.forEach {
8-
println(it)
941
}

0 commit comments

Comments
 (0)