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 cabbbf7

Browse filesBrowse files
committed
Handle 404 that represents "no license"
1 parent 59324b0 commit cabbbf7
Copy full SHA for cabbbf7

File tree

Expand file treeCollapse file tree

2 files changed

+11
-15
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-15
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
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -853,18 +853,20 @@ protected void wrapUp(GHCommitComment[] page) {
853853
* This is a preview item and subject to change.
854854
*
855855
* @throws IOException as usual but also if you don't use the preview connector
856+
* @return null if there's no license.
856857
*/
857858
@Preview @Deprecated
858859
public GHLicense getLicense() throws IOException{
859-
return getLicenseContent_().license;
860+
GHContentWithLicense lic = getLicenseContent_();
861+
return lic!=null ? lic.license : null;
860862
}
861863

862864
/**
863865
* Retrieves the contents of the repository's license file - makes an additional API call
864866
* <p>
865867
* This is a preview item and subject to change.
866868
*
867-
* @return details regarding the license contents
869+
* @return details regarding the license contents, or null if there's no license.
868870
* @throws IOException as usual but also if you don't use the preview connector
869871
*/
870872
@Preview @Deprecated
@@ -874,9 +876,13 @@ public GHContent getLicenseContent() throws IOException {
874876

875877
@Preview @Deprecated
876878
private GHContentWithLicense getLicenseContent_() throws IOException {
877-
return root.retrieve()
878-
.withHeader("Accept","application/vnd.github.drax-preview+json")
879-
.to(getApiTailUrl("license"), GHContentWithLicense.class).wrap(this);
879+
try {
880+
return root.retrieve()
881+
.withHeader("Accept","application/vnd.github.drax-preview+json")
882+
.to(getApiTailUrl("license"), GHContentWithLicense.class).wrap(this);
883+
} catch (FileNotFoundException e) {
884+
return null;
885+
}
880886
}
881887

882888
/**

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

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHLicenseTest.java
-10Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,6 @@ public void getLicense() throws IOException {
8989
assertTrue("The HTML URL is correct", license.getHtmlUrl().equals(new URL("http://choosealicense.com/licenses/mit/")));
9090
}
9191

92-
/**
93-
* Attempts to list the licenses with a non-preview connection
94-
*
95-
* @throws IOException is expected to be thrown
96-
*/
97-
@Test(expected = IOException.class)
98-
public void ListLicensesWithoutPreviewConnection() throws IOException {
99-
GitHub.connect().listLicenses();
100-
}
101-
10292
/**
10393
* Accesses the 'kohsuke/github-api' repo using {@link GitHub#getRepository(String)}
10494
* and checks that the license is correct

0 commit comments

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