Skip to content

Commit c956790

Browse files
authored
Add setup snippets to README (#72)
Add setup snippets to README and update example code.
1 parent 2fcb1a5 commit c956790

File tree

4 files changed

+156
-17
lines changed

4 files changed

+156
-17
lines changed

README.md

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,58 @@ That's it! You can now use the library without any code configuration from:
2727
- [Kotlin projects](./examples/example-project)
2828
- [Jupyter notebooks with the Kotlin kernel](./examples/example-notebooks)
2929

30+
### Setup snippets
31+
32+
<details>
33+
<summary>Add to a Kotlin script</summary>
34+
35+
```kotlin
36+
@file:Repository("https://jitpack.io")
37+
@file:DependsOn("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.16.0")
38+
```
39+
40+
</details>
41+
42+
<details>
43+
<summary>Add to a Kotlin project</summary>
44+
45+
Groovy
46+
47+
```groovy
48+
repositories {
49+
maven { url = 'https://jitpack.io' }
50+
}
51+
dependencies {
52+
implementation 'com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.16.0'
53+
}
54+
```
55+
56+
Kotlin
57+
58+
```kotlin
59+
repositories {
60+
maven(url = "https://jitpack.io")
61+
}
62+
dependencies {
63+
implementation("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.16.0")
64+
}
65+
```
66+
67+
</details>
68+
69+
<details>
70+
<summary>Add to a Jupyter notebook</summary>
71+
72+
```
73+
%useLatestDescriptors
74+
%use gradle-enterprise-api-kotlin(version=0.16.0)
75+
```
76+
77+
</details>
78+
3079
## Usage
3180

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

3584
```kotlin
@@ -63,18 +112,18 @@ finishes, as an [expected behavior of OkHttp][4].
63112
### Caching
64113

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

69118
### Extensions
70119

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

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

80129
```kotlin
@@ -88,14 +137,14 @@ builds.collect {
88137

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

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

95144
## Optional setup
96145

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

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

113162
## More info
114163

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

122171
```kotlin

examples/example-notebooks/MostFrequentBuilds.ipynb

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"outputs": [],
5353
"source": [
5454
"%useLatestDescriptors\n",
55-
"%use gradle-enterprise-api-kotlin(version=0.15.1)\n",
55+
"%use gradle-enterprise-api-kotlin(version=0.16.0)\n",
5656
"%use coroutines(v=1.7.1)"
5757
]
5858
},
@@ -153,7 +153,7 @@
153153
"\n",
154154
"val builds: List<GradleAttributes> = runBlocking {\n",
155155
" val startMilli = startDate.atStartOfDay(ZoneId.of(\"UTC\")).toInstant().toEpochMilli()\n",
156-
" GradleEnterprise.api.getGradleAttributesFlow(since = startMilli)\n",
156+
" GradleEnterpriseApi.buildsApi.getGradleAttributesFlow(since = startMilli)\n",
157157
" .filter(buildFilter)\n",
158158
" .printProgress { i, build ->\n",
159159
" val buildDate = Instant.ofEpochMilli(build.buildStartTime).atOffset(ZoneOffset.UTC)\n",
@@ -409,7 +409,96 @@
409409
"outputs": [
410410
{
411411
"data": {
412-
"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}]}",
412+
"application/kotlindataframe+json": {
413+
"columns": [
414+
"tasks",
415+
"count"
416+
],
417+
"kotlin_dataframe": [
418+
{
419+
"count": 3173,
420+
"tasks": "app:assembleBrazilDebug"
421+
},
422+
{
423+
"count": 974,
424+
"tasks": "IDE sync"
425+
},
426+
{
427+
"count": 205,
428+
"tasks": "droid-cli:installDist"
429+
},
430+
{
431+
"count": 147,
432+
"tasks": "clean"
433+
},
434+
{
435+
"count": 92,
436+
"tasks": "feature:order-delivery:customer-satisfaction:impl:compileReleaseSources"
437+
},
438+
{
439+
"count": 85,
440+
"tasks": "infrastructure:design-system:compose:compileReleaseSources"
441+
},
442+
{
443+
"count": 54,
444+
"tasks": "app:assembleBrazilDebug :app:installBrazilDebug"
445+
},
446+
{
447+
"count": 51,
448+
"tasks": "build-plugins:functionalTest --tests rasp.AndroidRaspProtectionPluginTest"
449+
},
450+
{
451+
"count": 44,
452+
"tasks": "analytics-braze:testReleaseUnitTest --tests br.com.ifood.analytics.braze.AppBrazeAnalyticsProviderTest"
453+
},
454+
{
455+
"count": 44,
456+
"tasks": "feature:survey:impl:compileReleaseSources"
457+
},
458+
{
459+
"count": 33,
460+
"tasks": "clean app:assembleBrazilDebug"
461+
},
462+
{
463+
"count": 31,
464+
"tasks": "feature:voucher-android-training:impl:compileReleaseSources"
465+
},
466+
{
467+
"count": 30,
468+
"tasks": "feature:search:impl:compileReleaseSources"
469+
},
470+
{
471+
"count": 29,
472+
"tasks": "droid-cli:run --args ci run-jupyter-notebook"
473+
},
474+
{
475+
"count": 27,
476+
"tasks": "clean :feature:internal-settings:sample:assemble"
477+
},
478+
{
479+
"count": 24,
480+
"tasks": "clean :app:assembleBrazilDebug"
481+
},
482+
{
483+
"count": 20,
484+
"tasks": "protectArtifact"
485+
},
486+
{
487+
"count": 19,
488+
"tasks": "analytics-braze:testReleaseUnitTest --tests br.com.ifood.analytics.braze.AppBrazeAnalyticsProviderTest.sendEvent_featureFlagCanSendEvent_sendEvent"
489+
},
490+
{
491+
"count": 19,
492+
"tasks": "setupDependencies"
493+
},
494+
{
495+
"count": 16,
496+
"tasks": "feature:checkout:core:impl:testReleaseUnitTest --tests br.com.ifood.checkout.presentation.plugin.standard.delivery.DeliveryPluginViewModelTest"
497+
}
498+
],
499+
"ncol": 2,
500+
"nrow": 682
501+
},
413502
"text/html": [
414503
" <html>\n",
415504
" <head>\n",

examples/example-project/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ repositories {
1313
}
1414

1515
dependencies {
16-
implementation("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.15.1")
16+
implementation("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.16.0")
1717
}

examples/example-script.main.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
*/
1717

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

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

0 commit comments

Comments
 (0)