22
33package com.gabrielfeo.gradle.enterprise.api.extension
44
5+ import com.gabrielfeo.gradle.enterprise.api.Config
56import com.gabrielfeo.gradle.enterprise.api.BuildsApi
67import com.gabrielfeo.gradle.enterprise.api.internal.API_MAX_BUILDS
78import com.gabrielfeo.gradle.enterprise.api.internal.operator.pagedUntilLastBuild
8- import com.gabrielfeo.gradle.enterprise.api.internal.operator.withGradleAttributes
99import com.gabrielfeo.gradle.enterprise.api.model.*
1010import kotlinx.coroutines.CoroutineScope
1111import kotlinx.coroutines.DelicateCoroutinesApi
@@ -17,15 +17,21 @@ import kotlinx.coroutines.flow.*
1717 * for queries of any size, as opposed to [BuildsApi.getBuilds] which is limited by the
1818 * API itself to 1000.
1919 *
20- * - Will request from the API until results end or an error occurs.
21- * - Use [Sequence.take] and similar functions to stop collecting early.
22- * - A subset of `getBuilds` params are supported
20+ * - Will request from the API until results end, collection stops or an error occurs.
21+ * - Parameters same as [BuildsApi.getBuilds].
22+ * - Using [query] is highly recommended for server-side filtering (equivalent to GE advanced
23+ * query).
24+ * - `maxBuilds` is the only unsupported parameter, because this Flow will instead fetch
25+ * continously. Use [Flow.take] to stop collecting at a specific count.
2326 */
2427fun BuildsApi.getBuildsFlow (
2528 since : Long = 0,
2629 sinceBuild : String? = null,
2730 fromInstant : Long? = null,
2831 fromBuild : String? = null,
32+ query : String? = null,
33+ reverse : Boolean? = null,
34+ maxWaitSecs : Int? = null,
2935 buildsPerPage : Int = API_MAX_BUILDS ,
3036): Flow <Build > {
3137 val api = this
@@ -35,6 +41,9 @@ fun BuildsApi.getBuildsFlow(
3541 sinceBuild = sinceBuild,
3642 fromInstant = fromInstant,
3743 fromBuild = fromBuild,
44+ query = query,
45+ reverse = reverse,
46+ maxWaitSecs = maxWaitSecs,
3847 maxBuilds = buildsPerPage,
3948 )
4049 val pagedBuilds = firstBuilds.asFlow().pagedUntilLastBuild(api, buildsPerPage)
@@ -43,13 +52,20 @@ fun BuildsApi.getBuildsFlow(
4352}
4453
4554/* *
46- * Gets [GradleAttributes] of all builds from a given date. Queries [BuildsApi.getBuilds]
47- * first, since it's the only endpoint providing a timeline of builds, then maps each to
48- * [BuildsApi.getGradleAttributes].
55+ * Gets [GradleAttributes] of all builds from a given date. Queries [BuildsApi.getBuilds] first,
56+ * the endpoint providing a timeline of builds, then maps each to [BuildsApi.getGradleAttributes].
4957 *
50- * Don't expect client-side filtering to be efficient. Will request up to [Int.MAX_VALUE]
51- * builds and their attributes concurrently and eagerly, with a buffer, in coroutines started in
52- * [scope]. For other params, see [getBuildsFlow] and [BuildsApi.getBuilds].
58+ * Instead of filtering builds downstream based on `GradleAttributes` (e.g. using [Flow.filter]),
59+ * prefer filtering server-side using a `query` (see [BuildsApi.getBuilds]).
60+ *
61+ * ### Buffering
62+ *
63+ * Will request eagerly and buffer up to [Int.MAX_VALUE] calls.
64+ *
65+ * ### Concurrency
66+ *
67+ * Attributes are requested concurrently in coroutines started in [scope]. The number of
68+ * concurrent requests underneath is still limited by [Config.maxConcurrentRequests].
5369 *
5470 * @param scope CoroutineScope in which to create coroutines. Defaults to [GlobalScope].
5571 */
@@ -59,13 +75,19 @@ fun BuildsApi.getGradleAttributesFlow(
5975 sinceBuild : String? = null,
6076 fromInstant : Long? = null,
6177 fromBuild : String? = null,
78+ query : String? = null,
79+ reverse : Boolean? = null,
80+ maxWaitSecs : Int? = null,
6281 scope : CoroutineScope = GlobalScope ,
6382): Flow <GradleAttributes > =
6483 getBuildsFlow(
6584 since = since,
6685 sinceBuild = sinceBuild,
6786 fromInstant = fromInstant,
68- fromBuild = fromBuild
87+ fromBuild = fromBuild,
88+ query = query,
89+ reverse = reverse,
90+ maxWaitSecs = maxWaitSecs,
6991 ).withGradleAttributes(scope, api = this ).map { (_, attrs) ->
7092 attrs
7193 }
0 commit comments