mirror of
https://github.com/jlengrand/github-api.git
synced 2026-04-19 00:11:22 +00:00
Add GitHub Contents API read methods
This commit is contained in:
committed by
Matt Farmer
parent
1283006b53
commit
925d26e54c
72
src/main/java/org/kohsuke/github/GHContent.java
Normal file
72
src/main/java/org/kohsuke/github/GHContent.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
/**
|
||||
* A Content of a repository.
|
||||
*
|
||||
* @author Alexandre COLLIGNON
|
||||
*/
|
||||
public final class GHContent {
|
||||
private GHRepository owner;
|
||||
|
||||
private String type;
|
||||
private String encoding;
|
||||
private long size;
|
||||
private String name;
|
||||
private String path;
|
||||
private String content;
|
||||
private String url; // this is the API url
|
||||
private String git_url; // this is the Blob url
|
||||
private String html_url; // this is the UI
|
||||
|
||||
public GHRepository getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getEncoding() {
|
||||
return encoding;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return new String(javax.xml.bind.DatatypeConverter.parseBase64Binary(getEncodedContent()));
|
||||
}
|
||||
|
||||
public String getEncodedContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getGitUrl() {
|
||||
return git_url;
|
||||
}
|
||||
|
||||
public String getHtmlUrl() {
|
||||
return html_url;
|
||||
}
|
||||
|
||||
public boolean isFile() {
|
||||
return "file".equals(type);
|
||||
}
|
||||
|
||||
public boolean isDirectory() {
|
||||
return "dir".equals(type);
|
||||
}
|
||||
}
|
||||
@@ -733,7 +733,21 @@ public class GHRepository {
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
public GHContent getFileContent(String path) throws IOException {
|
||||
return root.retrieve().to(String.format("/repos/%s/%s/contents/%s", owner.login, name, path), GHContent.class);
|
||||
}
|
||||
|
||||
public List<GHContent> getDirectoryContent(String path) throws IOException {
|
||||
GHContent[] files = root.retrieve().to(String.format("/repos/%s/%s/contents/%s", owner.login, name, path), GHContent[].class);
|
||||
|
||||
return Arrays.asList(files);
|
||||
}
|
||||
|
||||
public GHContent getReadme() throws Exception {
|
||||
return getFileContent("readme");
|
||||
}
|
||||
|
||||
public GHMilestone createMilestone(String title, String description) throws IOException {
|
||||
return new Requester(root)
|
||||
.with("title", title).with("description", description).method("POST").to(getApiTailUrl("milestones"), GHMilestone.class).wrap(this);
|
||||
|
||||
Reference in New Issue
Block a user