Skip to content

Commit 29d6ca3

Browse files
authored
Fix javadoc and update examples for 0.17.0 (#87)
Fix javadoc which still described pre-0.17.0 API. Also update examples for the new version and fix the `update-examples` workflow scripts, which were missing execute permissions and tried to edit ignored files.
1 parent f81b225 commit 29d6ca3

File tree

10 files changed

+49
-31
lines changed

10 files changed

+49
-31
lines changed

.github/scripts/replace_string.py

100644100755
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import argparse
44
from pathlib import Path
5+
import sys
6+
import git
7+
58

69
def main() -> None:
710
parser = argparse.ArgumentParser()
@@ -13,11 +16,20 @@ def main() -> None:
1316

1417

1518
def replace_string(path: Path, old_string: str, new_string: str) -> None:
19+
repo = git.Repo(path, search_parent_directories=True)
1620
for file in path.glob('**/*'):
17-
if file.is_file():
21+
if not should_replace(repo, file):
22+
continue
23+
try:
1824
text = file.read_text()
1925
text = text.replace(old_string, new_string)
2026
file.write_text(text)
27+
except UnicodeError as e:
28+
print(f'Error processing file {file}:', e, file=sys.stderr)
29+
30+
31+
def should_replace(repo, file):
32+
return file.is_file() and not repo.ignored(file) and file.parts[0] != '.git'
2133

2234

2335
if __name__ == "__main__":

.github/scripts/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GitPython==3.1.31

.github/scripts/test_replace_string.py

100644100755
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import unittest
4+
from unittest import mock
45
from pathlib import Path
56
from shutil import copytree
67
from tempfile import TemporaryDirectory
@@ -10,7 +11,9 @@
1011

1112
class TestReplaceString(unittest.TestCase):
1213

13-
def test_replace_string(self):
14+
@mock.patch('git.Repo')
15+
def test_replace_string(self, repo):
16+
repo.return_value.ignored.return_value = False
1417
old = '0.17.0'
1518
new = '0.17.1'
1619
files = ('README.md', 'build.gradle.kts', 'notebook.ipynb')

.github/workflows/pr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
steps:
2727
- name: Checkout
2828
uses: actions/checkout@v3
29+
- run: pip install -r .github/scripts/requirements.txt
2930
- name: 'unittest discover'
3031
run: python3 -m unittest discover -bs .github/scripts
3132

.github/workflows/update-examples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
steps:
1717
- name: 'Checkout'
1818
uses: actions/checkout@v3
19+
- run: pip install -r .github/scripts/requirements.txt
1920
- name: 'Get versions'
2021
run: |
2122
old_version="$(git tag --sort=-v:refname | head -n 2 | tail -n 1)"

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
# Gradle Enterprise API Kotlin
22

3-
[![Maven Central](https://img.shields.io/badge/Maven%20Central-0.16.2-blue)][14]
4-
[![Javadoc](https://img.shields.io/badge/Javadoc-0.16.2-orange)][7]
3+
[![Maven Central](https://img.shields.io/badge/Maven%20Central-0.17.0-blue)][14]
4+
[![Javadoc](https://img.shields.io/badge/Javadoc-0.17.0-orange)][7]
55

66
A Kotlin library to access the [Gradle Enterprise API][1], easy to use from:
77

88
- [Jupyter notebooks with the Kotlin kernel][29]
99
- [Kotlin scripts (`kts`)][27]
1010
- [Kotlin projects][28]
1111

12-
Using the API is as easy as this:
13-
1412
```kotlin
15-
GradleEnterpriseApi.buildsApi.getBuilds(since = yesterdayMilli).forEach {
13+
val api = GradleEnterpriseApi.newInstance()
14+
api.buildsApi.getBuilds(since = yesterdayMilli).forEach {
1615
println(it)
1716
}
1817
```
@@ -53,7 +52,7 @@ recommended over JitPack.
5352

5453
```
5554
%useLatestDescriptors
56-
%use gradle-enterprise-api-kotlin(version=0.16.2)
55+
%use gradle-enterprise-api-kotlin(version=0.17.0)
5756
```
5857

5958
</details>
@@ -62,7 +61,7 @@ recommended over JitPack.
6261
<summary>Add to a Kotlin script</summary>
6362

6463
```kotlin
65-
@file:DependsOn("com.gabrielfeo:gradle-enterprise-api-kotlin:0.16.2")
64+
@file:DependsOn("com.gabrielfeo:gradle-enterprise-api-kotlin:0.17.0")
6665
```
6766

6867
</details>
@@ -72,7 +71,7 @@ recommended over JitPack.
7271

7372
```kotlin
7473
dependencies {
75-
implementation("com.gabrielfeo:gradle-enterprise-api-kotlin:0.16.2")
74+
implementation("com.gabrielfeo:gradle-enterprise-api-kotlin:0.17.0")
7675
}
7776
```
7877

@@ -101,11 +100,13 @@ For example, [`BuildsApi`][20] contains all endpoints under `/api/builds/`:
101100

102101
### Calling the APIs
103102

104-
For simple use cases, you may use the companion instance ([DefaultInstance][23]) directly, as if
105-
calling static methods:
103+
API methods are generated as suspend functions.
104+
For most cases like scripts and notebooks, simply use [runBlocking][30]:
106105

107106
```kotlin
108-
GradleEnterpriseApi.buildsApi.getBuilds(since = yesterdayMilli)
107+
runBlocking {
108+
val builds: List<Build> = api.buildsApi.getBuilds(since = yesterdayMilli)
109+
}
109110
```
110111

111112
It's recommended to call [`GradleEnterpriseApi.shutdown()`][11] at the end of scripts to release
@@ -130,7 +131,7 @@ also takes care of paging under-the-hood, returning a [`Flow`][26] of all builds
130131
date, so you don't have to worry about the REST API's limit of 1000 builds per request:
131132

132133
```kotlin
133-
val builds = GradleEnterpriseApi.buildsApi.getGradleAttributesFlow(since = lastYear)
134+
val builds: Flow<GradleAttributes> = api.buildsApi.getGradleAttributesFlow(since = lastYear)
134135
builds.collect {
135136
// ...
136137
}
@@ -189,7 +190,7 @@ import com.gabrielfeo.gradle.enterprise.api.model.extension.*
189190
[11]: https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-gradle-enterprise-api/shutdown.html
190191
[12]: https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-config/-cache-config/cache-enabled.html
191192
[13]: https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-config/-cache-config/index.html
192-
[14]: https://central.sonatype.com/artifact/com.gabrielfeo/gradle-enterprise-api-kotlin/0.16.2
193+
[14]: https://central.sonatype.com/artifact/com.gabrielfeo/gradle-enterprise-api-kotlin/0.17.0
193194
[16]: https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-config/api-url.html
194195
[17]: https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-config/api-token.html
195196
[18]: https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-builds-api/index.html
@@ -204,3 +205,4 @@ import com.gabrielfeo.gradle.enterprise.api.model.extension.*
204205
[27]: ./examples/example-script.main.kts
205206
[28]: ./examples/example-project
206207
[29]: https://nbviewer.org/github/gabrielfeo/gradle-enterprise-api-kotlin/blob/main/examples/example-notebooks/MostFrequentBuilds.ipynb
208+
[30]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html

examples/example-notebooks/MostFrequentBuilds.ipynb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"Add libraries to use, via line magics. `%use` is a [line magic](https://github.com/Kotlin/kotlin-jupyter#line-magics) of the Kotlin kernel that can do much more than adding the library. To illustrate, this setup can be replaced with a single line magic.\n",
3636
"\n",
3737
"```kotlin\n",
38-
"@file:DependsOn(\"com.gabrielfeo:gradle-enterprise-api-kotlin:0.16.2\")\n",
38+
"@file:DependsOn(\"com.gabrielfeo:gradle-enterprise-api-kotlin:0.17.0\")\n",
3939
"\n",
4040
"import com.gabrielfeo.gradle.enterprise.api.*\n",
4141
"import com.gabrielfeo.gradle.enterprise.api.model.*\n",
@@ -45,7 +45,7 @@
4545
"is the same as:\n",
4646
"\n",
4747
"```\n",
48-
"%use gradle-enterprise-api-kotlin(version=0.16.2)\n",
48+
"%use gradle-enterprise-api-kotlin(version=0.17.0)\n",
4949
"```"
5050
]
5151
},
@@ -57,7 +57,7 @@
5757
"outputs": [],
5858
"source": [
5959
"%useLatestDescriptors\n",
60-
"%use gradle-enterprise-api-kotlin(version=0.16.2)\n",
60+
"%use gradle-enterprise-api-kotlin(version=0.17.0)\n",
6161
"%use coroutines(v=1.7.1)"
6262
]
6363
},
@@ -112,9 +112,10 @@
112112
"import java.time.temporal.*\n",
113113
"import java.util.LinkedList\n",
114114
"\n",
115+
"val api = GradleEnterpriseApi.newInstance()\n",
115116
"val builds: List<GradleAttributes> = runBlocking {\n",
116117
" val startMilli = startDate.atStartOfDay(ZoneId.of(\"UTC\")).toInstant().toEpochMilli()\n",
117-
" GradleEnterpriseApi.buildsApi.getGradleAttributesFlow(since = startMilli)\n",
118+
" api.buildsApi.getGradleAttributesFlow(since = startMilli)\n",
118119
" .filter(buildFilter)\n",
119120
" .toList(LinkedList())\n",
120121
"}"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ java {
1414
}
1515

1616
dependencies {
17-
implementation("com.gabrielfeo:gradle-enterprise-api-kotlin:0.16.2")
17+
implementation("com.gabrielfeo:gradle-enterprise-api-kotlin:0.17.0")
1818
}

examples/example-script.main.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* legacy tests. We should suggest they run test instead, leaving check for CI to run."
1616
*/
1717

18-
@file:DependsOn("com.gabrielfeo:gradle-enterprise-api-kotlin:0.16.2")
18+
@file:DependsOn("com.gabrielfeo:gradle-enterprise-api-kotlin:0.17.0")
1919

2020
import com.gabrielfeo.gradle.enterprise.api.*
2121
import com.gabrielfeo.gradle.enterprise.api.model.*
@@ -32,9 +32,10 @@ val buildFilter: (GradleAttributes) -> Boolean = { build ->
3232
}
3333

3434
// Fetch builds from the API
35+
val api = GradleEnterpriseApi.newInstance()
3536
val builds: List<GradleAttributes> = runBlocking {
3637
val startMilli = startDate.atStartOfDay(ZoneId.of("UTC")).toInstant().toEpochMilli()
37-
GradleEnterpriseApi.buildsApi.getGradleAttributesFlow(since = startMilli)
38+
api.buildsApi.getGradleAttributesFlow(since = startMilli)
3839
.filter(buildFilter)
3940
.toList(LinkedList())
4041
}

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.gabrielfeo.gradle.enterprise.api
33
import com.gabrielfeo.gradle.enterprise.api.internal.buildOkHttpClient
44
import com.gabrielfeo.gradle.enterprise.api.internal.buildRetrofit
55
import com.gabrielfeo.gradle.enterprise.api.internal.infrastructure.Serializer
6+
import okhttp3.OkHttpClient
67
import retrofit2.Retrofit
78
import retrofit2.create
89

@@ -15,15 +16,14 @@ import retrofit2.create
1516
* - [metaApi]
1617
* - [testDistributionApi]
1718
*
18-
* For simple use cases, you may use the companion instance ([DefaultInstance]) directly, as if
19-
* calling static methods:
19+
* Create an instance with [newInstance]:
2020
*
2121
* ```kotlin
22-
* GradleEnterpriseApi.buildsApi.getBuilds(...)
22+
* val api = GradleEnterpriseApi.newInstance()
23+
* api.buildsApi.getBuilds(...)
2324
* ```
2425
*
25-
* However, if you need to change [config] at runtime or own the instance's lifecycle (e.g.
26-
* with an IoC container like Dagger), create a new instance:
26+
* You may pass a default [Config], e.g. for sharing [OkHttpClient] resources:
2727
*
2828
* ```kotlin
2929
* val options = Options(clientBuilder = myOwnOkHttpClient.newBuilder())
@@ -48,10 +48,6 @@ interface GradleEnterpriseApi {
4848
*/
4949
fun shutdown()
5050

51-
/**
52-
* The default, companion instance of the Gradle Enterprise API client. See
53-
* [GradleEnterpriseApi].
54-
*/
5551
companion object {
5652

5753
/**

0 commit comments

Comments
 (0)