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 4f17d35

Browse filesBrowse files
authored
Merge pull request hub4j#411 from tadfisher/master
Add GHRepository.getRelease and GHRepository.getReleaseByTagName
2 parents 3cfcad7 + 75918c5 commit 4f17d35
Copy full SHA for 4f17d35

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+46
-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
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,22 @@ public GHRef createRef(String name, String sha) throws IOException {
308308
public List<GHRelease> getReleases() throws IOException {
309309
return listReleases().asList();
310310
}
311+
312+
public GHRelease getRelease(long id) throws IOException {
313+
try {
314+
return root.retrieve().to(getApiTailUrl("releases/" + id), GHRelease.class).wrap(this);
315+
} catch (FileNotFoundException e) {
316+
return null; // no release for this id
317+
}
318+
}
319+
320+
public GHRelease getReleaseByTagName(String tag) throws IOException {
321+
try {
322+
return root.retrieve().to(getApiTailUrl("releases/tags/" + tag), GHRelease.class).wrap(this);
323+
} catch (FileNotFoundException e) {
324+
return null; // no release for this tag
325+
}
326+
}
311327

312328
public GHRelease getLatestRelease() throws IOException {
313329
try {

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

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/RepositoryTest.java
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,36 @@ public void LatestRepositoryNotExist() {
9494
}
9595
}
9696

97+
@Test public void listReleases() throws IOException {
98+
PagedIterable<GHRelease> releases = gitHub.getOrganization("github").getRepository("hub").listReleases();
99+
assertTrue(releases.iterator().hasNext());
100+
}
101+
102+
@Test
103+
public void getReleaseExists() throws IOException {
104+
GHRelease release = gitHub.getOrganization("github").getRepository("hub").getRelease(6839710);
105+
assertEquals("v2.3.0-pre10", release.getTagName());
106+
}
107+
108+
@Test
109+
public void getReleaseDoesNotExist() throws IOException {
110+
GHRelease release = gitHub.getOrganization("github").getRepository("hub").getRelease(Long.MAX_VALUE);
111+
assertNull(release);
112+
}
113+
114+
@Test
115+
public void getReleaseByTagNameExists() throws IOException {
116+
GHRelease release = gitHub.getOrganization("github").getRepository("hub").getReleaseByTagName("v2.3.0-pre10");
117+
assertNotNull(release);
118+
assertEquals("v2.3.0-pre10", release.getTagName());
119+
}
120+
121+
@Test
122+
public void getReleaseByTagNameDoesNotExist() throws IOException {
123+
GHRelease release = getRepository().getReleaseByTagName("foo-bar-baz");
124+
assertNull(release);
125+
}
126+
97127
private GHRepository getRepository() throws IOException {
98128
return gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
99129
}

0 commit comments

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