From 1dbcc4b7765950d90194775db4ffe4f076f80ea7 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 15 Feb 2015 06:31:22 -0800 Subject: [PATCH] Fixed the getReadme() method. It was calling the wrong endpoint. Fixed issue #99. --- src/main/java/org/kohsuke/github/GHGist.java | 1 + src/main/java/org/kohsuke/github/GHRepository.java | 8 ++++++-- src/test/java/org/kohsuke/github/AppTest.java | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHGist.java b/src/main/java/org/kohsuke/github/GHGist.java index 6e3f35d989..801aef22d7 100644 --- a/src/main/java/org/kohsuke/github/GHGist.java +++ b/src/main/java/org/kohsuke/github/GHGist.java @@ -15,6 +15,7 @@ * @see GHUser#listGists() * @see GitHub#getGist(String) * @see GitHub#createGist() + * @see documentation */ public class GHGist extends GHObject { /*package almost final*/ GHUser owner; diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 599c09cf25..c0f36153c2 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -964,8 +964,12 @@ public List getDirectoryContent(String path, String ref) throws IOExc return Arrays.asList(files); } - public GHContent getReadme() throws Exception { - return getFileContent("readme"); + /** + * https://developer.github.com/v3/repos/contents/#get-the-readme + */ + public GHContent getReadme() throws IOException { + Requester requester = root.retrieve(); + return requester.to(getApiTailUrl("readme"), GHContent.class).wrap(this); } public GHContentUpdateResponse createContent(String content, String commitMessage, String path) throws IOException { diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 65074716fb..3afb464618 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -658,6 +658,13 @@ public void testIssueSearch() throws IOException { } } + @Test // issue #99 + public void testReadme() throws IOException { + GHContent readme = gitHub.getRepository("github-api-test-org/test-readme").getReadme(); + assertEquals(readme.getName(),"README.md"); + assertEquals(readme.getContent(),"This is a markdown readme.\n"); + } + private void kohsuke() { String login = getUser().getLogin(); Assume.assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));