Skip to content

Commit

Permalink
Merge pull request #343 from kamontat/feature/latest-release
Browse files Browse the repository at this point in the history
add latest release
  • Loading branch information
kohsuke authored Sep 8, 2017
2 parents 7ceca07 + 5554332 commit 2e2813f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ public GHRef createRef(String name, String sha) throws IOException {
public List<GHRelease> getReleases() throws IOException {
return listReleases().asList();
}

public GHRelease getLatestRelease() throws IOException {
try {
return root.retrieve().to(getApiTailUrl("releases/latest"), GHRelease.class).wrap(this);
} catch (FileNotFoundException e) {
return null; // no latest release
}
}

public PagedIterable<GHRelease> listReleases() throws IOException {
return new PagedIterable<GHRelease>() {
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/kohsuke/github/RepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,32 @@ public void getPermission() throws Exception {
}
}
}



@Test
public void LatestRepositoryExist() {
try {
// add the repository that have latest release
GHRelease release = gitHub.getRepository("kamontat/CheckIDNumber").getLatestRelease();
assertEquals("v3.0", release.getTagName());
} catch (IOException e) {
e.printStackTrace();
fail();
}
}

@Test
public void LatestRepositoryNotExist() {
try {
// add the repository that `NOT` have latest release
GHRelease release = gitHub.getRepository("kamontat/Java8Example").getLatestRelease();
assertNull(release);
} catch (IOException e) {
e.printStackTrace();
fail();
}
}

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

0 comments on commit 2e2813f

Please sign in to comment.