mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
Tree traversal from commit & its associated tests
This commit is contained in:
@@ -37,6 +37,12 @@ public class GHCommit {
|
||||
|
||||
private int comment_count;
|
||||
|
||||
static class Tree {
|
||||
String sha;
|
||||
}
|
||||
|
||||
private Tree tree;
|
||||
|
||||
@WithBridgeMethods(value = GHAuthor.class, castRequired = true)
|
||||
public GitUser getAuthor() {
|
||||
return author;
|
||||
@@ -224,6 +230,13 @@ public class GHCommit {
|
||||
return stats.deletions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to walk the tree
|
||||
*/
|
||||
public GHTree getTree() throws IOException {
|
||||
return owner.getTree(getCommitShortInfo().tree.sha);
|
||||
}
|
||||
|
||||
/**
|
||||
* URL of this commit like "https://github.com/kohsuke/sandbox-ant/commit/8ae38db0ea5837313ab5f39d43a6f73de3bd9000"
|
||||
*/
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.List;
|
||||
* https://developer.github.com/v3/git/trees/
|
||||
*
|
||||
* @author Daniel Teixeira - https://github.com/ddtxra
|
||||
* @see GHCommit#getTree()
|
||||
* @see GHRepository#getTree(String)
|
||||
* @see GHTreeEntry#asTree()
|
||||
*/
|
||||
@@ -35,6 +36,19 @@ public class GHTree {
|
||||
return Collections.unmodifiableList(Arrays.asList(tree));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a tree entry by its name.
|
||||
*
|
||||
* IOW, find a directory entry by a file name.
|
||||
*/
|
||||
public GHTreeEntry getEntry(String path) {
|
||||
for (GHTreeEntry e : tree) {
|
||||
if (e.getPath().equals(path))
|
||||
return e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the number of items in the tree array exceeded the GitHub maximum limit.
|
||||
* @return true true if the number of items in the tree array exceeded the GitHub maximum limit otherwise false.
|
||||
|
||||
@@ -363,6 +363,11 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
||||
assertEquals(48,f.getLinesChanged());
|
||||
assertEquals("modified",f.getStatus());
|
||||
assertEquals("changelog.html", f.getFileName());
|
||||
|
||||
// walk the tree
|
||||
GHTree t = commit.getTree();
|
||||
assertThat(IOUtils.toString(t.getEntry("todo.txt").readAsBlob()), containsString("executor rendering"));
|
||||
assertNotNull(t.getEntry("war").asTree());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user