Skip to content

Commit 78f533b

Browse files
authored
Merge pull request #977 from skaldarnar/feat/528-ghrelease-assets
Include assets directly in GHRelease
2 parents 8ababb6 + 79c7dd9 commit 78f533b

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/main/java/org/kohsuke/github/GHRelease.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Release in a github repository.
1616
*
1717
* @see GHRepository#getReleases() GHRepository#getReleases()
18+
* @see GHRepository#listReleases() () GHRepository#listReleases()
1819
* @see GHRepository#createRelease(String) GHRepository#createRelease(String)
1920
*/
2021
public class GHRelease extends GHObject {
@@ -23,6 +24,7 @@ public class GHRelease extends GHObject {
2324

2425
private String html_url;
2526
private String assets_url;
27+
private List<GHAsset> assets;
2628
private String upload_url;
2729
private String tag_name;
2830
private String target_commitish;
@@ -249,18 +251,45 @@ public GHAsset uploadAsset(String filename, InputStream stream, String contentTy
249251
}
250252

251253
/**
252-
* Gets assets.
254+
* Get the cached assets.
255+
*
256+
* @return the assets
257+
*
258+
* @deprecated This should be the default behavior of {@link #getAssets()} in a future release. This method is
259+
* introduced in addition to enable a transition to using cached asset information while keeping the
260+
* existing logic in place for backwards compatibility.
261+
*/
262+
@Deprecated
263+
@Preview
264+
public List<GHAsset> assets() {
265+
return assets;
266+
}
267+
268+
/**
269+
* Re-fetch the assets of this release.
253270
*
254271
* @return the assets
255272
* @throws IOException
256273
* the io exception
274+
* @deprecated The behavior of this method will change in a future release. It will then provide cached assets as
275+
* provided by {@link #assets()}. Use {@link #listAssets()} instead to fetch up-to-date information of
276+
* assets.
257277
*/
278+
@Deprecated
258279
public List<GHAsset> getAssets() throws IOException {
259-
Requester builder = owner.root.createRequest();
280+
return listAssets().toList();
281+
}
260282

261-
return builder.withUrlPath(getApiTailUrl("assets"))
262-
.toIterable(GHAsset[].class, item -> item.wrap(this))
263-
.toList();
283+
/**
284+
* Re-fetch the assets of this release.
285+
*
286+
* @return the assets
287+
* @throws IOException
288+
* the io exception
289+
*/
290+
public PagedIterable<GHAsset> listAssets() throws IOException {
291+
Requester builder = owner.root.createRequest();
292+
return builder.withUrlPath(getApiTailUrl("assets")).toIterable(GHAsset[].class, item -> item.wrap(this));
264293
}
265294

266295
/**

src/test/java/org/kohsuke/github/LifecycleTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ private void deleteAsset(GHRelease release, GHAsset asset) throws IOException {
5656
private GHAsset uploadAsset(GHRelease release) throws IOException {
5757
GHAsset asset = release.uploadAsset(new File("LICENSE.txt"), "application/text");
5858
assertNotNull(asset);
59+
List<GHAsset> cachedAssets = release.assets();
60+
assertEquals(0, cachedAssets.size());
5961
List<GHAsset> assets = release.getAssets();
6062
assertEquals(1, assets.size());
6163
assertEquals("LICENSE.txt", assets.get(0).getName());

0 commit comments

Comments
 (0)