File tree Expand file tree Collapse file tree
src/main/java/org/kohsuke/github Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010/**
1111 * @author Kanstantsin Shautsou
1212 * @author Kohsuke Kawaguchi
13+ * @see GHTreeEntry#asBlob()
1314 * @see GHRepository#getBlob(String)
1415 * @see <a href="https://developer.github.com/v3/git/blobs/#get-a-blob">Get a blob</a>
1516 */
Original file line number Diff line number Diff line change 1111 *
1212 * @author Daniel Teixeira - https://github.com/ddtxra
1313 * @see GHRepository#getTree(String)
14+ * @see GHTreeEntry#asTree()
1415 */
1516public class GHTree {
1617 /* package almost final */ GHRepository repo ;
Original file line number Diff line number Diff line change 11package org .kohsuke .github ;
22
3+ import java .io .IOException ;
4+ import java .io .InputStream ;
35import java .net .URL ;
46
57/**
@@ -70,4 +72,37 @@ public String getSha() {
7072 public URL getUrl () {
7173 return GitHub .parseURL (url );
7274 }
75+
76+ /**
77+ * If this tree entry represents a file, then return its information.
78+ * Otherwise null.
79+ */
80+ public GHBlob asBlob () throws IOException {
81+ if (type .equals ("blob" ))
82+ return tree .repo .getBlob (sha );
83+ else
84+ return null ;
85+ }
86+
87+ /**
88+ * If this tree entry represents a file, then return its content.
89+ * Otherwise null.
90+ */
91+ public InputStream readAsBlob () throws IOException {
92+ if (type .equals ("blob" ))
93+ return tree .repo .readBlob (sha );
94+ else
95+ return null ;
96+ }
97+
98+ /**
99+ * If this tree entry represents a directory, then return it.
100+ * Otherwise null.
101+ */
102+ public GHTree asTree () throws IOException {
103+ if (type .equals ("tree" ))
104+ return tree .repo .getTree (sha );
105+ else
106+ return null ;
107+ }
73108}
You can’t perform that action at this time.
0 commit comments