diff --git a/src/main/java/com/spotify/github/v3/clients/GitDataClient.java b/src/main/java/com/spotify/github/v3/clients/GitDataClient.java index 3abb45fc..760a474c 100644 --- a/src/main/java/com/spotify/github/v3/clients/GitDataClient.java +++ b/src/main/java/com/spotify/github/v3/clients/GitDataClient.java @@ -249,6 +249,17 @@ public CompletableFuture getTree(final String sha) { return github.request(path, Tree.class); } + /** + * Get a repository tree recursively. + * + * @param sha commit sha + * @return tree + */ + public CompletableFuture getRecursiveTree(final String sha) { + final String path = String.format(TREE_SHA_URI_TEMPLATE, owner, repo, sha); + return github.request(path + "?recursive=true", Tree.class); + } + /** * Set a repository tree. * diff --git a/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java b/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java index 8b3b2757..3874dd74 100644 --- a/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java @@ -256,6 +256,22 @@ public void testGetTree() throws IOException { assertThat(tree.sha(), is("9c27bd92524e2b57b569d4c86695b3993d9b8f9f")); } + @Test + public void testGetRecursiveTree() throws IOException { + final CompletableFuture fixture = + completedFuture(json.fromJson(getFixture("recursive-tree.json"), Tree.class)); + + when(github.request("/repos/someowner/somerepo/git/trees/thesha", Tree.class)) + .thenReturn(fixture); + + final Tree tree = + gitDataClient + .getTree("thesha") + .join(); + assertThat(tree.sha(), is("9c27bd92524e2b57b569d4c86695b3993d9b8f9f")); + assertThat(tree.tree().size(), is(7)); + } + @Test public void testCreateTree() throws IOException { final TreeItem treeItem = diff --git a/src/test/resources/com/spotify/github/v3/clients/recursive-tree.json b/src/test/resources/com/spotify/github/v3/clients/recursive-tree.json new file mode 100644 index 00000000..9cd1876d --- /dev/null +++ b/src/test/resources/com/spotify/github/v3/clients/recursive-tree.json @@ -0,0 +1,61 @@ +{ + "sha": "9c27bd92524e2b57b569d4c86695b3993d9b8f9f", + "url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/trees/9c27bd92524e2b57b569d4c86695b3993d9b8f9f", + "tree": [ + { + "path": "README.md", + "mode": "100644", + "type": "blob", + "sha": "6e091fd045dc88806e5c70357326af7fa0e1ccde", + "size": 12, + "url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/blobs/6e091fd045dc88806e5c70357326af7fa0e1ccde" + }, + { + "path": "UserGeneratedContentUtils.java", + "mode": "100644", + "type": "blob", + "sha": "77b3e188803e717a0a5ce53b818b0ed6fb6b8a23", + "size": 5340, + "url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/blobs/77b3e188803e717a0a5ce53b818b0ed6fb6b8a23" + }, + { + "path": "readme.md", + "mode": "100644", + "type": "blob", + "sha": "f09eac953086b8760f600822f057141d7b311165", + "size": 29, + "url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/blobs/f09eac953086b8760f600822f057141d7b311165" + }, + { + "path": "src", + "mode": "040000", + "type": "tree", + "sha": "26cd96e1394d6c4982d8cec879ad4fefa423bec8", + "url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/trees/26cd96e1394d6c4982d8cec879ad4fefa423bec8" + }, + { + "path": "src/public", + "mode": "040000", + "type": "tree", + "sha": "a296470ebb9709103115d6e21d9bc54cdfc8b120", + "url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/trees/a296470ebb9709103115d6e21d9bc54cdfc8b120" + }, + { + "path": "src/public/UserGeneratedContentUtils.java", + "mode": "100644", + "type": "blob", + "sha": "77b3e188803e717a0a5ce53b818b0ed6fb6b8a23", + "size": 5340, + "url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/blobs/77b3e188803e717a0a5ce53b818b0ed6fb6b8a23" + }, + { + "path": "src/public/test.txt", + "mode": "100644", + "type": "blob", + "sha": "c57eff55ebc0c54973903af5f72bac72762cf4f4", + "size": 12, + "url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/blobs/c57eff55ebc0c54973903af5f72bac72762cf4f4" + } + ], + "truncated": false +}