From 379a050ec97099463dc3a90fbc82ad0f1f0f68bc Mon Sep 17 00:00:00 2001 From: Gabriel Feo Date: Thu, 28 Mar 2024 13:42:16 +0000 Subject: [PATCH] Support 2023.4 models param (#162) 2023.4 supports passing a models parameter to `/api/builds` to get GradleAttributes and others in a single request. `getGradleAttributesFlow` is deprecated in favor of the new parameter. --- library/build.gradle.kts | 15 +++++++++++++++ .../api/extension/BuildsApiExtensions.kt | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 552d52c7..a8a067a7 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -124,6 +124,21 @@ tasks.openApiGenerate.configure { } } } + // Fix mapping of BuildModelName: gradle-attributes -> gradleAttributes + doLast { + ant.withGroovyBuilder { + "replaceregexp"( + "match" to "Minus", + "replace" to "", + "flags" to "mg", + ) { + "fileset"( + "dir" to srcDir, + "includes" to "com/gabrielfeo/gradle/enterprise/api/model/BuildModelName.kt", + ) + } + } + } } sourceSets { diff --git a/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/extension/BuildsApiExtensions.kt b/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/extension/BuildsApiExtensions.kt index 52dbd90e..42ddad13 100644 --- a/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/extension/BuildsApiExtensions.kt +++ b/library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/extension/BuildsApiExtensions.kt @@ -32,6 +32,7 @@ fun BuildsApi.getBuildsFlow( reverse: Boolean? = null, maxWaitSecs: Int? = null, buildsPerPage: Int = API_MAX_BUILDS, + models: List? = null, ): Flow { return flow { var builds = getBuilds( @@ -43,6 +44,7 @@ fun BuildsApi.getBuildsFlow( reverse = reverse, maxWaitSecs = maxWaitSecs, maxBuilds = buildsPerPage, + models = models, ) emitAll(builds.asFlow()) while (builds.isNotEmpty()) { @@ -76,6 +78,18 @@ fun BuildsApi.getBuildsFlow( * * @param scope CoroutineScope in which to create coroutines. Defaults to [GlobalScope]. */ +@Deprecated( + "Use `getBuildsFlow(models = listOf(BuildModelName.gradleAttributes))` instead. " + + "This function will be removed in the next release.", + replaceWith = ReplaceWith( + "getBuildsFlow(since, sinceBuild, fromInstant, fromBuild, query, reverse," + + "maxWaitSecs, models = listOf(BuildModelName.gradleAttributes))", + imports = [ + "com.gabrielfeo.gradle.enterprise.api.extension.getBuildsFlow", + "com.gabrielfeo.gradle.enterprise.api.model.BuildModelName", + ] + ), +) @OptIn(DelicateCoroutinesApi::class) fun BuildsApi.getGradleAttributesFlow( since: Long = 0, @@ -86,6 +100,7 @@ fun BuildsApi.getGradleAttributesFlow( reverse: Boolean? = null, maxWaitSecs: Int? = null, scope: CoroutineScope = GlobalScope, + models: List? = null, ): Flow = getBuildsFlow( since = since, @@ -95,6 +110,7 @@ fun BuildsApi.getGradleAttributesFlow( query = query, reverse = reverse, maxWaitSecs = maxWaitSecs, + models = models, ).withGradleAttributes(scope, api = this).map { (_, attrs) -> attrs }