Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2e2813f

Browse filesBrowse files
authored
Merge pull request hub4j#343 from kamontat/feature/latest-release
add latest release
2 parents 7ceca07 + 5554332 commit 2e2813f
Copy full SHA for 2e2813f

File tree

Expand file treeCollapse file tree

2 files changed

+34
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+34
-0
lines changed

‎src/main/java/org/kohsuke/github/GHRepository.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ public GHRef createRef(String name, String sha) throws IOException {
298298
public List<GHRelease> getReleases() throws IOException {
299299
return listReleases().asList();
300300
}
301+
302+
public GHRelease getLatestRelease() throws IOException {
303+
try {
304+
return root.retrieve().to(getApiTailUrl("releases/latest"), GHRelease.class).wrap(this);
305+
} catch (FileNotFoundException e) {
306+
return null; // no latest release
307+
}
308+
}
301309

302310
public PagedIterable<GHRelease> listReleases() throws IOException {
303311
return new PagedIterable<GHRelease>() {

‎src/test/java/org/kohsuke/github/RepositoryTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/RepositoryTest.java
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,32 @@ public void getPermission() throws Exception {
6767
}
6868
}
6969
}
70+
71+
72+
73+
@Test
74+
public void LatestRepositoryExist() {
75+
try {
76+
// add the repository that have latest release
77+
GHRelease release = gitHub.getRepository("kamontat/CheckIDNumber").getLatestRelease();
78+
assertEquals("v3.0", release.getTagName());
79+
} catch (IOException e) {
80+
e.printStackTrace();
81+
fail();
82+
}
83+
}
84+
85+
@Test
86+
public void LatestRepositoryNotExist() {
87+
try {
88+
// add the repository that `NOT` have latest release
89+
GHRelease release = gitHub.getRepository("kamontat/Java8Example").getLatestRelease();
90+
assertNull(release);
91+
} catch (IOException e) {
92+
e.printStackTrace();
93+
fail();
94+
}
95+
}
7096

7197
private GHRepository getRepository() throws IOException {
7298
return gitHub.getOrganization("github-api-test-org").getRepository("jenkins");

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.