Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit 1dbcc4b

Browse files
committed
Fixed the getReadme() method.
It was calling the wrong endpoint. Fixed issue hub4j#99.
1 parent 18696fc commit 1dbcc4b

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/main/java/org/kohsuke/github/GHGist.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* @see GHUser#listGists()
1616
* @see GitHub#getGist(String)
1717
* @see GitHub#createGist()
18+
* @see <a href="https://developer.github.com/v3/gists/">documentation</a>
1819
*/
1920
public class GHGist extends GHObject {
2021
/*package almost final*/ GHUser owner;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,12 @@ public List<GHContent> getDirectoryContent(String path, String ref) throws IOExc
964964
return Arrays.asList(files);
965965
}
966966

967-
public GHContent getReadme() throws Exception {
968-
return getFileContent("readme");
967+
/**
968+
* https://developer.github.com/v3/repos/contents/#get-the-readme
969+
*/
970+
public GHContent getReadme() throws IOException {
971+
Requester requester = root.retrieve();
972+
return requester.to(getApiTailUrl("readme"), GHContent.class).wrap(this);
969973
}
970974

971975
public GHContentUpdateResponse createContent(String content, String commitMessage, String path) throws IOException {

src/test/java/org/kohsuke/github/AppTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,13 @@ public void testIssueSearch() throws IOException {
658658
}
659659
}
660660

661+
@Test // issue #99
662+
public void testReadme() throws IOException {
663+
GHContent readme = gitHub.getRepository("github-api-test-org/test-readme").getReadme();
664+
assertEquals(readme.getName(),"README.md");
665+
assertEquals(readme.getContent(),"This is a markdown readme.\n");
666+
}
667+
661668
private void kohsuke() {
662669
String login = getUser().getLogin();
663670
Assume.assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));

0 commit comments

Comments
 (0)