-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93c1bb4
commit b3bcf0f
Showing
4 changed files
with
83 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/ApiConstants.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.gabrielfeo.gradle.enterprise.api.internal | ||
|
||
import com.gabrielfeo.gradle.enterprise.api.GradleEnterpriseApi | ||
|
||
/** | ||
* Undocumented max value of `/api/builds?maxBuilds`. Last checked in 2022.4. | ||
*/ | ||
internal const val API_MAX_BUILDS = 1000 |
34 changes: 34 additions & 0 deletions
34
...main/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/operator/pagedUntilLastBuild.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.gabrielfeo.gradle.enterprise.api.internal.operator | ||
|
||
import com.gabrielfeo.gradle.enterprise.api.* | ||
import com.gabrielfeo.gradle.enterprise.api.internal.API_MAX_BUILDS | ||
import com.gabrielfeo.gradle.enterprise.api.model.* | ||
import kotlinx.coroutines.flow.* | ||
import retrofit2.await | ||
|
||
/** | ||
* Emits all available builds starting from the upstream Flow builds until the last build available. | ||
* Makes paged requests to the API using `fromBuild`, [maxPerRequest] at a time. | ||
*/ | ||
internal fun Flow<Build>.pagedUntilLastBuild( | ||
maxPerRequest: Int, | ||
): Flow<Build> { | ||
val firstBuilds = this | ||
return flow { | ||
var lastBuildId = "" | ||
firstBuilds.collect { | ||
lastBuildId = it.id | ||
emit(it) | ||
} | ||
if (lastBuildId.isEmpty()) { | ||
return@flow | ||
} else while (true) { | ||
val builds = api.getBuilds(fromBuild = lastBuildId, maxBuilds = maxPerRequest).await() | ||
emitAll(builds.asFlow()) | ||
when { | ||
builds.isEmpty() || builds.size < API_MAX_BUILDS -> break | ||
else -> lastBuildId = builds.last().id | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ain/kotlin/com/gabrielfeo/gradle/enterprise/api/internal/operator/withGradleAttributes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.gabrielfeo.gradle.enterprise.api.internal.operator | ||
|
||
import com.gabrielfeo.gradle.enterprise.api.* | ||
import com.gabrielfeo.gradle.enterprise.api.model.* | ||
import kotlinx.coroutines.* | ||
import kotlinx.coroutines.flow.* | ||
import retrofit2.await | ||
|
||
/** | ||
* Joins builds with their [GradleAttributes], which comes from a different endpoint | ||
* ([GradleEnterpriseApi.getGradleAttributes]). | ||
* | ||
* Don't expect client-side filtering to be efficient. Does as many concurrent calls | ||
* as it can, requesting attributes in an eager coroutine, in [scope]. | ||
*/ | ||
internal fun Flow<Build>.withGradleAttributes( | ||
scope: CoroutineScope, | ||
): Flow<Pair<Build, GradleAttributes>> = | ||
map { build -> | ||
build to scope.async { | ||
api.getGradleAttributes(build.id).await() | ||
} | ||
}.buffer(Int.MAX_VALUE).map { (build, attrs) -> | ||
build to attrs.await() | ||
} |