Skip to content

Commit

Permalink
Merge pull request #224 from Shredder121/directory-content-trailing-s…
Browse files Browse the repository at this point in the history
…lash

Remove trailing slash when requesting directory content
  • Loading branch information
kohsuke committed Dec 1, 2015
2 parents c33f05e + a1e79d3 commit f868969
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,9 @@ public List<GHContent> getDirectoryContent(String path) throws IOException {

public List<GHContent> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GHContent> 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);
Expand Down

0 comments on commit f868969

Please sign in to comment.