forked from hub4j/github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GHTree.java
95 lines (84 loc) · 2.18 KB
/
GHTree.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package org.kohsuke.github;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
// TODO: Auto-generated Javadoc
/**
* Provides information for Git Trees https://developer.github.com/v3/git/trees/
*
* @author Daniel Teixeira - https://github.com/ddtxra
* @see GHCommit#getTree() GHCommit#getTree()
* @see GHRepository#getTree(String) GHRepository#getTree(String)
* @see GHTreeEntry#asTree() GHTreeEntry#asTree()
*/
public class GHTree {
/** The repo. */
/* package almost final */GHRepository repo;
private boolean truncated;
private String sha, url;
private GHTreeEntry[] tree;
/**
* The SHA for this trees.
*
* @return the sha
*/
public String getSha() {
return sha;
}
/**
* Return an array of entries of the trees.
*
* @return the tree
*/
public List<GHTreeEntry> getTree() {
return Collections.unmodifiableList(Arrays.asList(tree));
}
/**
* Finds a tree entry by its name.
* <p>
* IOW, find a directory entry by a file name.
*
* @param path
* the path
* @return the entry
*/
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 if the number of items in the tree array exceeded the GitHub maximum limit otherwise false.
*/
public boolean isTruncated() {
return truncated;
}
/**
* The API URL of this tag, such as "url":
* "https://api.github.com/repos/octocat/Hello-World/trees/fc6274d15fa3ae2ab983129fb037999f264ba9a7",
*
* @return the url
*/
public URL getUrl() {
return GitHubClient.parseURL(url);
}
/**
* Wrap.
*
* @param repo
* the repo
* @return the GH tree
*/
GHTree wrap(GHRepository repo) {
this.repo = repo;
for (GHTreeEntry e : tree) {
e.tree = this;
}
return this;
}
}