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 f868969

Browse filesBrowse files
committed
Merge pull request hub4j#224 from Shredder121/directory-content-trailing-slash
Remove trailing slash when requesting directory content
2 parents c33f05e + a1e79d3 commit f868969
Copy full SHA for f868969

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+11
-0
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
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,9 @@ public List<GHContent> getDirectoryContent(String path) throws IOException {
11021102

11031103
public List<GHContent> getDirectoryContent(String path, String ref) throws IOException {
11041104
Requester requester = root.retrieve();
1105+
while (path.endsWith("/")) {
1106+
path = path.substring(0, path.length() - 1);
1107+
}
11051108
String target = getApiTailUrl("contents/" + path);
11061109

11071110
GHContent[] files = requester.with("ref",ref).to(target, GHContent[].class);

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

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHContentIntegrationTest.java
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ public void testGetDirectoryContent() throws Exception {
4343
assertTrue(entries.size() == 3);
4444
}
4545

46+
@Test
47+
public void testGetDirectoryContentTrailingSlash() throws Exception {
48+
//Used to truncate the ?ref=master, see gh-224 https://github.com/kohsuke/github-api/pull/224
49+
List<GHContent> entries = repo.getDirectoryContent("ghcontent-ro/a-dir-with-3-entries/", "master");
50+
51+
assertTrue(entries.get(0).getUrl().endsWith("?ref=master"));
52+
}
53+
4654
@Test
4755
public void testCRUDContent() throws Exception {
4856
GHContentUpdateResponse created = repo.createContent("this is an awesome file I created\n", "Creating a file for integration tests.", createdFilename);

0 commit comments

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