Skip to content

Commit f24f563

Browse files
Add api method for getting recursive tree (#78)
Coverage is ok, PR is tested
1 parent 2da809a commit f24f563

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

src/main/java/com/spotify/github/v3/clients/GitDataClient.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,17 @@ public CompletableFuture<Tree> getTree(final String sha) {
249249
return github.request(path, Tree.class);
250250
}
251251

252+
/**
253+
* Get a repository tree recursively.
254+
*
255+
* @param sha commit sha
256+
* @return tree
257+
*/
258+
public CompletableFuture<Tree> getRecursiveTree(final String sha) {
259+
final String path = String.format(TREE_SHA_URI_TEMPLATE, owner, repo, sha);
260+
return github.request(path + "?recursive=true", Tree.class);
261+
}
262+
252263
/**
253264
* Set a repository tree.
254265
*

src/test/java/com/spotify/github/v3/clients/GitDataClientTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,22 @@ public void testGetTree() throws IOException {
256256
assertThat(tree.sha(), is("9c27bd92524e2b57b569d4c86695b3993d9b8f9f"));
257257
}
258258

259+
@Test
260+
public void testGetRecursiveTree() throws IOException {
261+
final CompletableFuture<Tree> fixture =
262+
completedFuture(json.fromJson(getFixture("recursive-tree.json"), Tree.class));
263+
264+
when(github.request("/repos/someowner/somerepo/git/trees/thesha", Tree.class))
265+
.thenReturn(fixture);
266+
267+
final Tree tree =
268+
gitDataClient
269+
.getTree("thesha")
270+
.join();
271+
assertThat(tree.sha(), is("9c27bd92524e2b57b569d4c86695b3993d9b8f9f"));
272+
assertThat(tree.tree().size(), is(7));
273+
}
274+
259275
@Test
260276
public void testCreateTree() throws IOException {
261277
final TreeItem treeItem =
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"sha": "9c27bd92524e2b57b569d4c86695b3993d9b8f9f",
3+
"url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/trees/9c27bd92524e2b57b569d4c86695b3993d9b8f9f",
4+
"tree": [
5+
{
6+
"path": "README.md",
7+
"mode": "100644",
8+
"type": "blob",
9+
"sha": "6e091fd045dc88806e5c70357326af7fa0e1ccde",
10+
"size": 12,
11+
"url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/blobs/6e091fd045dc88806e5c70357326af7fa0e1ccde"
12+
},
13+
{
14+
"path": "UserGeneratedContentUtils.java",
15+
"mode": "100644",
16+
"type": "blob",
17+
"sha": "77b3e188803e717a0a5ce53b818b0ed6fb6b8a23",
18+
"size": 5340,
19+
"url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/blobs/77b3e188803e717a0a5ce53b818b0ed6fb6b8a23"
20+
},
21+
{
22+
"path": "readme.md",
23+
"mode": "100644",
24+
"type": "blob",
25+
"sha": "f09eac953086b8760f600822f057141d7b311165",
26+
"size": 29,
27+
"url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/blobs/f09eac953086b8760f600822f057141d7b311165"
28+
},
29+
{
30+
"path": "src",
31+
"mode": "040000",
32+
"type": "tree",
33+
"sha": "26cd96e1394d6c4982d8cec879ad4fefa423bec8",
34+
"url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/trees/26cd96e1394d6c4982d8cec879ad4fefa423bec8"
35+
},
36+
{
37+
"path": "src/public",
38+
"mode": "040000",
39+
"type": "tree",
40+
"sha": "a296470ebb9709103115d6e21d9bc54cdfc8b120",
41+
"url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/trees/a296470ebb9709103115d6e21d9bc54cdfc8b120"
42+
},
43+
{
44+
"path": "src/public/UserGeneratedContentUtils.java",
45+
"mode": "100644",
46+
"type": "blob",
47+
"sha": "77b3e188803e717a0a5ce53b818b0ed6fb6b8a23",
48+
"size": 5340,
49+
"url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/blobs/77b3e188803e717a0a5ce53b818b0ed6fb6b8a23"
50+
},
51+
{
52+
"path": "src/public/test.txt",
53+
"mode": "100644",
54+
"type": "blob",
55+
"sha": "c57eff55ebc0c54973903af5f72bac72762cf4f4",
56+
"size": 12,
57+
"url": "https://ghe.spotify.net/api/v3/repos/ugc-sharing/test-repo/git/blobs/c57eff55ebc0c54973903af5f72bac72762cf4f4"
58+
}
59+
],
60+
"truncated": false
61+
}

0 commit comments

Comments
 (0)