Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 60 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,58 @@ That's it! You can now use the library without any code configuration from:
- [Kotlin projects](./examples/example-project)
- [Jupyter notebooks with the Kotlin kernel](./examples/example-notebooks)

### Setup snippets

<details>
<summary>Add to a Kotlin script</summary>

```kotlin
@file:Repository("https://jitpack.io")
@file:DependsOn("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.16.0")
```

</details>

<details>
<summary>Add to a Kotlin project</summary>

Groovy

```groovy
repositories {
maven { url = 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.16.0'
}
```

Kotlin

```kotlin
repositories {
maven(url = "https://jitpack.io")
}
dependencies {
implementation("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.16.0")
}
```

</details>

<details>
<summary>Add to a Jupyter notebook</summary>

```
%useLatestDescriptors
%use gradle-enterprise-api-kotlin(version=0.16.0)
```

</details>

## Usage

The [`GradleEnterpriseApi`][9] interface represents the Gradle Enterprise REST API. It contains
The [`GradleEnterpriseApi`][9] interface represents the Gradle Enterprise REST API. It contains
the 4 APIs exactly as listed in the [REST API Manual][5]:

```kotlin
Expand Down Expand Up @@ -63,18 +112,18 @@ finishes, as an [expected behavior of OkHttp][4].
### Caching

HTTP caching is available, which can speed up queries significantly, but is
off by default. Enable by simply setting [`GRADLE_ENTERPRISE_API_CACHE_ENABLED`][12] to `true`. See
off by default. Enable by simply setting [`GRADLE_ENTERPRISE_API_CACHE_ENABLED`][12] to `true`. See
[`CacheConfig`][13] for caveats.

### Extensions

Explore the library's convenience extensions:
[`com.gabrielfeo.gradle.enterprise.api.extension`][25].

What you'll probably use the most is [`getGradleAttributesFlow`][24], which will call
What you'll probably use the most is [`getGradleAttributesFlow`][24], which will call
`/api/builds` to get the list of build IDs since a given date and join each with
`/api/builds/{id}/gradle-attributes`, which contains tags and custom values on each build. It
also takes care of paging under-the-hood, returning a [`Flow`][26] of all builds since the given
`/api/builds/{id}/gradle-attributes`, which contains tags and custom values on each build. It
also takes care of paging under-the-hood, returning a [`Flow`][26] of all builds since the given
date, so you don't have to worry about the REST API's limit of 1000 builds per request:

```kotlin
Expand All @@ -88,14 +137,14 @@ builds.collect {

[![Javadoc](https://img.shields.io/badge/javadoc-latest-orange)][7]

The javadoc of API interfaces and models, such as [`BuildsApi`][18] and [`GradleAttributes`][19],
matches the [REST API Manual][5] exactly. Both these classes and Gradle's own manual are generated
The javadoc of API interfaces and models, such as [`BuildsApi`][18] and [`GradleAttributes`][19],
matches the [REST API Manual][5] exactly. Both these classes and Gradle's own manual are generated
from the same OpenAPI spec.

## Optional setup

Creating a custom [`Config`][8] allows you to change library settings via code instead of
environment variables. It also lets you share resource between the library's `OkHttpClient` and
Creating a custom [`Config`][8] allows you to change library settings via code instead of
environment variables. It also lets you share resource between the library's `OkHttpClient` and
your own. For example:

```kotlin
Expand All @@ -112,11 +161,11 @@ See the [`Config`][8] documentation for more.

## More info

- Currently built for Gradle Enterprise `2022.4`, but should work fine with previous and
- Currently built for Gradle Enterprise `2022.4`, but should work fine with previous and
future versions. The library will be updated regularly for new API versions.
- Use JDK 8 or 14+ to run, if you want to avoid the ["illegal reflective access" warning about
Retrofit][3]
- All classes live in these packages. If you need to make small edits to scripts where there's
- All classes live in these packages. If you need to make small edits to scripts where there's
no auto-complete, wildcard imports can be used:

```kotlin
Expand Down
95 changes: 92 additions & 3 deletions examples/example-notebooks/MostFrequentBuilds.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"outputs": [],
"source": [
"%useLatestDescriptors\n",
"%use gradle-enterprise-api-kotlin(version=0.15.1)\n",
"%use gradle-enterprise-api-kotlin(version=0.16.0)\n",
"%use coroutines(v=1.7.1)"
]
},
Expand Down Expand Up @@ -153,7 +153,7 @@
"\n",
"val builds: List<GradleAttributes> = runBlocking {\n",
" val startMilli = startDate.atStartOfDay(ZoneId.of(\"UTC\")).toInstant().toEpochMilli()\n",
" GradleEnterprise.api.getGradleAttributesFlow(since = startMilli)\n",
" GradleEnterpriseApi.buildsApi.getGradleAttributesFlow(since = startMilli)\n",
" .filter(buildFilter)\n",
" .printProgress { i, build ->\n",
" val buildDate = Instant.ofEpochMilli(build.buildStartTime).atOffset(ZoneOffset.UTC)\n",
Expand Down Expand Up @@ -409,7 +409,96 @@
"outputs": [
{
"data": {
"application/kotlindataframe+json": "{\"nrow\":682,\"ncol\":2,\"columns\":[\"tasks\",\"count\"],\"kotlin_dataframe\":[{\"tasks\":\"app:assembleBrazilDebug\",\"count\":3173},{\"tasks\":\"IDE sync\",\"count\":974},{\"tasks\":\"droid-cli:installDist\",\"count\":205},{\"tasks\":\"clean\",\"count\":147},{\"tasks\":\"feature:order-delivery:customer-satisfaction:impl:compileReleaseSources\",\"count\":92},{\"tasks\":\"infrastructure:design-system:compose:compileReleaseSources\",\"count\":85},{\"tasks\":\"app:assembleBrazilDebug :app:installBrazilDebug\",\"count\":54},{\"tasks\":\"build-plugins:functionalTest --tests rasp.AndroidRaspProtectionPluginTest\",\"count\":51},{\"tasks\":\"analytics-braze:testReleaseUnitTest --tests br.com.ifood.analytics.braze.AppBrazeAnalyticsProviderTest\",\"count\":44},{\"tasks\":\"feature:survey:impl:compileReleaseSources\",\"count\":44},{\"tasks\":\"clean app:assembleBrazilDebug\",\"count\":33},{\"tasks\":\"feature:voucher-android-training:impl:compileReleaseSources\",\"count\":31},{\"tasks\":\"feature:search:impl:compileReleaseSources\",\"count\":30},{\"tasks\":\"droid-cli:run --args ci run-jupyter-notebook\",\"count\":29},{\"tasks\":\"clean :feature:internal-settings:sample:assemble\",\"count\":27},{\"tasks\":\"clean :app:assembleBrazilDebug\",\"count\":24},{\"tasks\":\"protectArtifact\",\"count\":20},{\"tasks\":\"analytics-braze:testReleaseUnitTest --tests br.com.ifood.analytics.braze.AppBrazeAnalyticsProviderTest.sendEvent_featureFlagCanSendEvent_sendEvent\",\"count\":19},{\"tasks\":\"setupDependencies\",\"count\":19},{\"tasks\":\"feature:checkout:core:impl:testReleaseUnitTest --tests br.com.ifood.checkout.presentation.plugin.standard.delivery.DeliveryPluginViewModelTest\",\"count\":16}]}",
"application/kotlindataframe+json": {
"columns": [
"tasks",
"count"
],
"kotlin_dataframe": [
{
"count": 3173,
"tasks": "app:assembleBrazilDebug"
},
{
"count": 974,
"tasks": "IDE sync"
},
{
"count": 205,
"tasks": "droid-cli:installDist"
},
{
"count": 147,
"tasks": "clean"
},
{
"count": 92,
"tasks": "feature:order-delivery:customer-satisfaction:impl:compileReleaseSources"
},
{
"count": 85,
"tasks": "infrastructure:design-system:compose:compileReleaseSources"
},
{
"count": 54,
"tasks": "app:assembleBrazilDebug :app:installBrazilDebug"
},
{
"count": 51,
"tasks": "build-plugins:functionalTest --tests rasp.AndroidRaspProtectionPluginTest"
},
{
"count": 44,
"tasks": "analytics-braze:testReleaseUnitTest --tests br.com.ifood.analytics.braze.AppBrazeAnalyticsProviderTest"
},
{
"count": 44,
"tasks": "feature:survey:impl:compileReleaseSources"
},
{
"count": 33,
"tasks": "clean app:assembleBrazilDebug"
},
{
"count": 31,
"tasks": "feature:voucher-android-training:impl:compileReleaseSources"
},
{
"count": 30,
"tasks": "feature:search:impl:compileReleaseSources"
},
{
"count": 29,
"tasks": "droid-cli:run --args ci run-jupyter-notebook"
},
{
"count": 27,
"tasks": "clean :feature:internal-settings:sample:assemble"
},
{
"count": 24,
"tasks": "clean :app:assembleBrazilDebug"
},
{
"count": 20,
"tasks": "protectArtifact"
},
{
"count": 19,
"tasks": "analytics-braze:testReleaseUnitTest --tests br.com.ifood.analytics.braze.AppBrazeAnalyticsProviderTest.sendEvent_featureFlagCanSendEvent_sendEvent"
},
{
"count": 19,
"tasks": "setupDependencies"
},
{
"count": 16,
"tasks": "feature:checkout:core:impl:testReleaseUnitTest --tests br.com.ifood.checkout.presentation.plugin.standard.delivery.DeliveryPluginViewModelTest"
}
],
"ncol": 2,
"nrow": 682
},
"text/html": [
" <html>\n",
" <head>\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/example-project/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ repositories {
}

dependencies {
implementation("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.15.1")
implementation("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.16.0")
}
5 changes: 3 additions & 2 deletions examples/example-script.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
*/

@file:Repository("https://jitpack.io")
@file:DependsOn("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.15.1")
@file:DependsOn("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.16.0")

import com.gabrielfeo.gradle.enterprise.api.*
import com.gabrielfeo.gradle.enterprise.api.model.*
import com.gabrielfeo.gradle.enterprise.api.extension.*
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import java.time.*
Expand Down Expand Up @@ -58,7 +59,7 @@ fun <T> Flow<T>.printProgress(produceMsg: (i: Int, current: T) -> String): Flow<
// Fetch builds from the API
val builds: List<GradleAttributes> = runBlocking {
val startMilli = startDate.atStartOfDay(ZoneId.of("UTC")).toInstant().toEpochMilli()
GradleEnterprise.api.getGradleAttributesFlow(since = startMilli)
GradleEnterpriseApi.buildsApi.getGradleAttributesFlow(since = startMilli)
.filter(buildFilter)
.printProgress { i, build ->
val buildDate = Instant.ofEpochMilli(build.buildStartTime).atOffset(ZoneOffset.UTC)
Expand Down