diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index f77ac6e2e8..e444fe4657 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -1102,6 +1102,9 @@ public List getDirectoryContent(String path) throws IOException { public List getDirectoryContent(String path, String ref) throws IOException { Requester requester = root.retrieve(); + while (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } String target = getApiTailUrl("contents/" + path); GHContent[] files = requester.with("ref",ref).to(target, GHContent[].class); diff --git a/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java b/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java index 39f8545aaa..7848143a86 100644 --- a/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java +++ b/src/test/java/org/kohsuke/github/GHContentIntegrationTest.java @@ -43,6 +43,14 @@ public void testGetDirectoryContent() throws Exception { assertTrue(entries.size() == 3); } + @Test + public void testGetDirectoryContentTrailingSlash() throws Exception { + //Used to truncate the ?ref=master, see gh-224 https://github.com/kohsuke/github-api/pull/224 + List entries = repo.getDirectoryContent("ghcontent-ro/a-dir-with-3-entries/", "master"); + + assertTrue(entries.get(0).getUrl().endsWith("?ref=master")); + } + @Test public void testCRUDContent() throws Exception { GHContentUpdateResponse created = repo.createContent("this is an awesome file I created\n", "Creating a file for integration tests.", createdFilename);