Skip to content

Commit 379a050

Browse files
authored
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.
1 parent 1502513 commit 379a050

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

library/build.gradle.kts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ tasks.openApiGenerate.configure {
124124
}
125125
}
126126
}
127+
// Fix mapping of BuildModelName: gradle-attributes -> gradleAttributes
128+
doLast {
129+
ant.withGroovyBuilder {
130+
"replaceregexp"(
131+
"match" to "Minus",
132+
"replace" to "",
133+
"flags" to "mg",
134+
) {
135+
"fileset"(
136+
"dir" to srcDir,
137+
"includes" to "com/gabrielfeo/gradle/enterprise/api/model/BuildModelName.kt",
138+
)
139+
}
140+
}
141+
}
127142
}
128143

129144
sourceSets {

library/src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/extension/BuildsApiExtensions.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ fun BuildsApi.getBuildsFlow(
3232
reverse: Boolean? = null,
3333
maxWaitSecs: Int? = null,
3434
buildsPerPage: Int = API_MAX_BUILDS,
35+
models: List<BuildModelName>? = null,
3536
): Flow<Build> {
3637
return flow {
3738
var builds = getBuilds(
@@ -43,6 +44,7 @@ fun BuildsApi.getBuildsFlow(
4344
reverse = reverse,
4445
maxWaitSecs = maxWaitSecs,
4546
maxBuilds = buildsPerPage,
47+
models = models,
4648
)
4749
emitAll(builds.asFlow())
4850
while (builds.isNotEmpty()) {
@@ -76,6 +78,18 @@ fun BuildsApi.getBuildsFlow(
7678
*
7779
* @param scope CoroutineScope in which to create coroutines. Defaults to [GlobalScope].
7880
*/
81+
@Deprecated(
82+
"Use `getBuildsFlow(models = listOf(BuildModelName.gradleAttributes))` instead. " +
83+
"This function will be removed in the next release.",
84+
replaceWith = ReplaceWith(
85+
"getBuildsFlow(since, sinceBuild, fromInstant, fromBuild, query, reverse," +
86+
"maxWaitSecs, models = listOf(BuildModelName.gradleAttributes))",
87+
imports = [
88+
"com.gabrielfeo.gradle.enterprise.api.extension.getBuildsFlow",
89+
"com.gabrielfeo.gradle.enterprise.api.model.BuildModelName",
90+
]
91+
),
92+
)
7993
@OptIn(DelicateCoroutinesApi::class)
8094
fun BuildsApi.getGradleAttributesFlow(
8195
since: Long = 0,
@@ -86,6 +100,7 @@ fun BuildsApi.getGradleAttributesFlow(
86100
reverse: Boolean? = null,
87101
maxWaitSecs: Int? = null,
88102
scope: CoroutineScope = GlobalScope,
103+
models: List<BuildModelName>? = null,
89104
): Flow<GradleAttributes> =
90105
getBuildsFlow(
91106
since = since,
@@ -95,6 +110,7 @@ fun BuildsApi.getGradleAttributesFlow(
95110
query = query,
96111
reverse = reverse,
97112
maxWaitSecs = maxWaitSecs,
113+
models = models,
98114
).withGradleAttributes(scope, api = this).map { (_, attrs) ->
99115
attrs
100116
}

0 commit comments

Comments
 (0)