diff --git a/pom.xml b/pom.xml
index 1e1161d95b..52c763940e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,11 +3,11 @@
org.kohsuke
pom
- 6
+ 8
github-api
- 1.53
+ 1.54
GitHub API for Java
http://github-api.kohsuke.org/
GitHub API for Java
@@ -16,7 +16,7 @@
scm:git:git@github.com/kohsuke/${project.artifactId}.git
scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git
http://${project.artifactId}.kohsuke.org/
- github-api-1.53
+ HEAD
@@ -35,7 +35,7 @@
com.infradna.tool
bridge-method-injector
- 1.8
+ 1.12
@@ -77,7 +77,7 @@
com.infradna.tool
bridge-method-annotation
- 1.8
+ 1.12
org.kohsuke.stapler
diff --git a/src/main/java/org/kohsuke/github/GHContent.java b/src/main/java/org/kohsuke/github/GHContent.java
index 61c474fa6f..443dd5918d 100644
--- a/src/main/java/org/kohsuke/github/GHContent.java
+++ b/src/main/java/org/kohsuke/github/GHContent.java
@@ -1,6 +1,8 @@
package org.kohsuke.github;
import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
import javax.xml.bind.DatatypeConverter;
@@ -8,7 +10,9 @@
* A Content of a repository.
*
* @author Alexandre COLLIGNON
+ * @see GHRepository#getFileContent(String)
*/
+@SuppressWarnings({"UnusedDeclaration"})
public class GHContent {
private GHRepository owner;
@@ -105,6 +109,25 @@ public boolean isDirectory() {
return "dir".equals(type);
}
+ /**
+ * List immediate children of this directory.
+ */
+ public PagedIterable listDirectoryContent() throws IOException {
+ if (!isDirectory())
+ throw new IllegalStateException(path+" is not a directory");
+
+ return new PagedIterable() {
+ public PagedIterator iterator() {
+ return new PagedIterator(owner.root.retrieve().asIterator(url, GHContent[].class)) {
+ @Override
+ protected void wrapUp(GHContent[] page) {
+ GHContent.wrap(page,owner);
+ }
+ };
+ }
+ };
+ }
+
public GHContentUpdateResponse update(String newContent, String commitMessage) throws IOException {
return update(newContent, commitMessage, null);
}
diff --git a/src/main/java/org/kohsuke/github/GHDeployKey.java b/src/main/java/org/kohsuke/github/GHDeployKey.java
new file mode 100644
index 0000000000..6e4ed496a6
--- /dev/null
+++ b/src/main/java/org/kohsuke/github/GHDeployKey.java
@@ -0,0 +1,46 @@
+package org.kohsuke.github;
+
+import java.io.IOException;
+
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+public class GHDeployKey {
+
+ protected String url, key, title;
+ protected boolean verified;
+ protected int id;
+ private GHRepository owner;
+
+ public int getId() {
+ return id;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public boolean isVerified() {
+ return verified;
+ }
+
+ public GHDeployKey wrap(GHRepository repo) {
+ this.owner = repo;
+ return this;
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this).append("title",title).append("id",id).append("key",key).toString();
+ }
+
+ public void delete() throws IOException {
+ new Requester(owner.root).method("DELETE").to(String.format("/repos/%s/%s/keys/%d", owner.getOwnerName(), owner.getName(), id));
+ }
+}
diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java
index 7a9fd28eb6..5dfe545057 100644
--- a/src/main/java/org/kohsuke/github/GHRepository.java
+++ b/src/main/java/org/kohsuke/github/GHRepository.java
@@ -561,7 +561,19 @@ public GHRef[] getRefs() throws IOException {
public GHRef[] getRefs(String refType) throws IOException {
return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refType), GHRef[].class);
}
-
+ /**
+ * Retrive a ref of the given type for the current GitHub repository.
+ *
+ * @param refName
+ * eg: heads/branch
+ * @return refs matching the request type
+ * @throws IOException
+ * on failure communicating with GitHub, potentially due to an
+ * invalid ref type being requested
+ */
+ public GHRef getRef(String refName) throws IOException {
+ return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refName), GHRef.class);
+ }
/**
* Gets a commit object in this repository.
*/
@@ -907,6 +919,22 @@ public GHMilestone createMilestone(String title, String description) throws IOEx
return new Requester(root)
.with("title", title).with("description", description).method("POST").to(getApiTailUrl("milestones"), GHMilestone.class).wrap(this);
}
+
+ public GHDeployKey addDeployKey(String title,String key) throws IOException {
+ return new Requester(root)
+ .with("title", title).with("key", key).method("POST").to(getApiTailUrl("keys"), GHDeployKey.class).wrap(this);
+
+ }
+
+ public List getDeployKeys() throws IOException{
+ List list = new ArrayList(Arrays.asList(
+ root.retrieve().to(String.format("/repos/%s/%s/keys", owner.login, name), GHDeployKey[].class)));
+ for (GHDeployKey h : list)
+ h.wrap(this);
+ return list;
+ }
+
+
@Override
public String toString() {
diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java
index d12b44683f..a1c231953a 100644
--- a/src/test/java/org/kohsuke/github/AppTest.java
+++ b/src/test/java/org/kohsuke/github/AppTest.java
@@ -3,6 +3,7 @@
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -20,6 +21,9 @@
import org.kohsuke.github.GHCommit.File;
import org.kohsuke.github.GHOrganization.Permission;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
import java.util.Date;
/**
@@ -529,6 +533,39 @@ public void testCreateRelease() throws Exception {
}
}
+ @Test
+ public void testRef() throws IOException {
+ GHRef masterRef = gitHub.getRepository("jenkinsci/jenkins").getRef("heads/master");
+ assertEquals("https://api.github.com/repos/jenkinsci/jenkins/git/refs/heads/master", masterRef.getUrl().toString());
+ }
+
+ @Test
+ public void directoryListing() throws IOException {
+ List children = gitHub.getRepository("jenkinsci/jenkins").getDirectoryContent("core");
+ for (GHContent c : children) {
+ System.out.println(c.getName());
+ if (c.isDirectory()) {
+ for (GHContent d : c.listDirectoryContent()) {
+ System.out.println(" "+d.getName());
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testAddDeployKey() throws IOException {
+ GHRepository myRepository = Iterables.get(gitHub.getMyself().getRepositories().values(),0);
+ final GHDeployKey newDeployKey = myRepository.addDeployKey("test", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC55wA5wHqTFMk3OkyHqtmgSAmIanREVP4ukMrPZFzYfRBaKYPCbBRxu7ddzF3oZ+i6ZV8+rH8hvhQTYl5LtOIxLUppsVVNSB9YKXQv37LLaWul9WoJPdXHGWfR3wlhRXsg1sMPpbgu60lXAl7xvx729FEjKEEHRMGkPbcIeHkov/tlEg9oQdqFC1Pqnv/lCsZ5UKRPLHY3V9pmSaEplwmwb//HppNtEYr9t6VNvOMjqbUrbhsilKu0t6qa3G7Kb47kvfJwMn+DKD2XJMYHYHMyHtHcFK8RIOSX8I+Bu4yeVmvcooSL65FBCIrmVoejkI7gZWDfgWVRboQ9RyB+VeXL example@example.com");
+ assertNotNull(newDeployKey.getId());
+
+ Iterables.find( myRepository.getDeployKeys(),new Predicate() {
+ public boolean apply(GHDeployKey deployKey) {
+ return newDeployKey.getId() == deployKey.getId() ;
+ }
+ });
+ newDeployKey.delete();
+ }
+
private void kohsuke() {
String login = getUser().getLogin();
Assume.assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));