Skip to content

Commit f61e4b3

Browse files
committed
Make methods of GradleEnterpriseApi suspend
Even with useCoroutines, openapi-generator outputs methods with Response<> wrapping by default. Response<> shouldn't be useful here, so they're replaced with the bare types.
1 parent 7588ee4 commit f61e4b3

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

build.gradle.kts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ openApiGenerate {
3737
packageName.set("com.gabrielfeo.gradle.enterprise.api.internal")
3838
invokerPackage.set("com.gabrielfeo.gradle.enterprise.api.internal")
3939
additionalProperties.put("library", "jvm-retrofit2")
40+
additionalProperties.put("useCoroutines", true)
41+
}
42+
43+
tasks.openApiGenerate.configure {
44+
// Replace Response<X> with X in every method return type of GradleEnterpriseApi.kt
45+
doLast {
46+
val apiFile = File(
47+
outputDir.get(),
48+
"src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApi.kt",
49+
)
50+
ant.withGroovyBuilder {
51+
"replaceregexp"(
52+
"file" to apiFile,
53+
"match" to ": Response<(.*?)>$",
54+
"replace" to """: \1""",
55+
"flags" to "gm",
56+
)
57+
}
58+
}
4059
}
4160

4261
sourceSets {

src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/ApiExtensions.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import kotlinx.coroutines.CoroutineScope
88
import kotlinx.coroutines.DelicateCoroutinesApi
99
import kotlinx.coroutines.GlobalScope
1010
import kotlinx.coroutines.flow.*
11-
import retrofit2.await
1211

1312
/**
1413
* Gets builds on demand from the API, in as many requests as necessary. It allows
@@ -31,7 +30,7 @@ fun GradleEnterpriseApi.getBuildsFlow(
3130
fromInstant = fromInstant,
3231
fromBuild = fromBuild,
3332
maxBuilds = API_MAX_BUILDS,
34-
).await()
33+
)
3534
val pagedBuilds = firstBuilds.asFlow().pagedUntilLastBuild(maxPerRequest = API_MAX_BUILDS)
3635
emitAll(pagedBuilds)
3736
}

src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/operator/pagedUntilLastBuild.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal fun Flow<Build>.pagedUntilLastBuild(
2323
if (lastBuildId.isEmpty()) {
2424
return@flow
2525
} else while (true) {
26-
val builds = api.getBuilds(fromBuild = lastBuildId, maxBuilds = maxPerRequest).await()
26+
val builds = api.getBuilds(fromBuild = lastBuildId, maxBuilds = maxPerRequest)
2727
emitAll(builds.asFlow())
2828
when {
2929
builds.isEmpty() || builds.size < API_MAX_BUILDS -> break

src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/operator/withGradleAttributes.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal fun Flow<Build>.withGradleAttributes(
1818
): Flow<Pair<Build, GradleAttributes>> =
1919
map { build ->
2020
build to scope.async {
21-
api.getGradleAttributes(build.id).await()
21+
api.getGradleAttributes(build.id)
2222
}
2323
}.buffer(Int.MAX_VALUE).map { (build, attrs) ->
2424
build to attrs.await()

0 commit comments

Comments
 (0)