File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Filter options
main/java/org/kohsuke/github
test/java/org/kohsuke/github Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Original file line number Diff line number Diff line change @@ -308,6 +308,22 @@ public GHRef createRef(String name, String sha) throws IOException {
308
308
public List <GHRelease > getReleases () throws IOException {
309
309
return listReleases ().asList ();
310
310
}
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
+ }
311
327
312
328
public GHRelease getLatestRelease () throws IOException {
313
329
try {
Original file line number Diff line number Diff line change @@ -94,6 +94,36 @@ public void LatestRepositoryNotExist() {
94
94
}
95
95
}
96
96
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
+
97
127
private GHRepository getRepository () throws IOException {
98
128
return gitHub .getOrganization ("github-api-test-org" ).getRepository ("jenkins" );
99
129
}
You can’t perform that action at this time.
0 commit comments