Skip to content

Commit

Permalink
Support 2023.4 models param (#162)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gabrielfeo authored Mar 28, 2024
1 parent 1502513 commit 379a050
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fun BuildsApi.getBuildsFlow(
reverse: Boolean? = null,
maxWaitSecs: Int? = null,
buildsPerPage: Int = API_MAX_BUILDS,
models: List<BuildModelName>? = null,
): Flow<Build> {
return flow {
var builds = getBuilds(
Expand All @@ -43,6 +44,7 @@ fun BuildsApi.getBuildsFlow(
reverse = reverse,
maxWaitSecs = maxWaitSecs,
maxBuilds = buildsPerPage,
models = models,
)
emitAll(builds.asFlow())
while (builds.isNotEmpty()) {
Expand Down Expand Up @@ -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,
Expand All @@ -86,6 +100,7 @@ fun BuildsApi.getGradleAttributesFlow(
reverse: Boolean? = null,
maxWaitSecs: Int? = null,
scope: CoroutineScope = GlobalScope,
models: List<BuildModelName>? = null,
): Flow<GradleAttributes> =
getBuildsFlow(
since = since,
Expand All @@ -95,6 +110,7 @@ fun BuildsApi.getGradleAttributesFlow(
query = query,
reverse = reverse,
maxWaitSecs = maxWaitSecs,
models = models,
).withGradleAttributes(scope, api = this).map { (_, attrs) ->
attrs
}

0 comments on commit 379a050

Please sign in to comment.