Recording parent GHRepository

This commit is contained in:
Kohsuke Kawaguchi
2016-12-17 07:03:40 -08:00
parent 2d7d4bbd4e
commit 88d52c44ad
3 changed files with 10 additions and 5 deletions

View File

@@ -800,7 +800,7 @@ public class GHRepository extends GHObject {
*/
public GHTree getTree(String sha) throws IOException {
String url = String.format("/repos/%s/%s/git/trees/%s", getOwnerName(), name, sha);
return root.retrieve().to(url, GHTree.class).wrap(root);
return root.retrieve().to(url, GHTree.class).wrap(this);
}
/**
@@ -815,7 +815,7 @@ public class GHRepository extends GHObject {
*/
public GHTree getTreeRecursive(String sha, int recursive) throws IOException {
String url = String.format("/repos/%s/%s/git/trees/%s?recursive=%d", getOwnerName(), name, sha, recursive);
return root.retrieve().to(url, GHTree.class).wrap(root);
return root.retrieve().to(url, GHTree.class).wrap(this);
}
/**

View File

@@ -13,7 +13,7 @@ import java.util.List;
* @see GHRepository#getTree(String)
*/
public class GHTree {
/* package almost final */GitHub root;
/* package almost final */GHRepository repo;
private boolean truncated;
private String sha, url;
@@ -50,8 +50,11 @@ public class GHTree {
return GitHub.parseURL(url);
}
/* package */GHTree wrap(GitHub root) {
this.root = root;
/* package */GHTree wrap(GHRepository repo) {
this.repo = repo;
for (GHTreeEntry e : tree) {
e.tree = this;
}
return this;
}

View File

@@ -10,6 +10,8 @@ import java.net.URL;
* @see GHTree
*/
public class GHTreeEntry {
/* package almost final */GHTree tree;
private String path, mode, type, sha, url;
private long size;