Compare commits

...

9 Commits

Author SHA1 Message Date
Kohsuke Kawaguchi
40a8c110bf [maven-release-plugin] prepare release github-api-1.29 2012-06-18 12:51:25 -07:00
Kohsuke Kawaguchi
c9cd0a4d1f added a simple CRUD test 2012-06-18 12:50:47 -07:00
Kohsuke Kawaguchi
45eae77f8f added missing repository delete operation 2012-06-18 12:50:40 -07:00
Kohsuke Kawaguchi
926202900c fixed a bug in editing the repository definition 2012-06-18 12:37:27 -07:00
Kohsuke Kawaguchi
21aa669503 redundant test case 2012-06-18 12:24:30 -07:00
Kohsuke Kawaguchi
dee28e7a7a Doc says this is asynchronous 2012-06-18 12:23:48 -07:00
Kohsuke Kawaguchi
c8f46a3666 needs to wrap up 2012-06-18 12:23:34 -07:00
Kohsuke Kawaguchi
ba7fe10a08 bug fix 2012-06-18 12:23:20 -07:00
Kohsuke Kawaguchi
9e9db72878 [maven-release-plugin] prepare for next development iteration 2012-06-13 08:27:58 -07:00
5 changed files with 32 additions and 17 deletions

View File

@@ -7,7 +7,7 @@
</parent>
<artifactId>github-api</artifactId>
<version>1.28</version>
<version>1.29</version>
<name>GitHub API for Java</name>
<url>http://github-api.kohsuke.org/</url>
<description>GitHub API for Java</description>

View File

@@ -45,7 +45,7 @@ public class GHOrganization extends GHPerson {
GHTeam[] teams = root.retrieveWithAuth("/orgs/" + login + "/teams", GHTeam[].class);
Map<String,GHTeam> r = new TreeMap<String, GHTeam>();
for (GHTeam t : teams) {
r.put(t.getName(),t);
r.put(t.getName(),t.wrapUp(this));
}
return r;
}

View File

@@ -32,6 +32,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.URL;
import java.util.AbstractSet;
import java.util.ArrayList;
@@ -269,8 +270,11 @@ public class GHRepository {
}
private void edit(String key, String value) throws IOException {
new Poster(root).withCredential().with(key,value)
.to("/repos/" + owner.login + "/" + name,null,"PATCH");
Poster poster = new Poster(root).withCredential();
if (!key.equals("name"))
poster.with("name", name); // even when we don't change the name, we need to send it in
poster.with(key, value)
.to("/repos/" + owner.login + "/" + name, null, "PATCH");
}
/**
@@ -310,12 +314,7 @@ public class GHRepository {
* Deletes this repository.
*/
public void delete() throws IOException {
throw new UnsupportedOperationException(); // doesn't appear to be available in V3
// Poster poster = new Poster(root).withCredential();
// String url = "/repos/delete/" + owner.login +"/"+name;
//
// DeleteToken token = poster.to(url, DeleteToken.class);
// poster.with("delete_token", token.delete_token).to(url);
new Poster(root).withCredential().to("/repos/" + owner.login +"/"+name, null, "DELETE");
}
/**
@@ -336,7 +335,18 @@ public class GHRepository {
*/
public GHRepository forkTo(GHOrganization org) throws IOException {
new Poster(root).withCredential().to(String.format("/repos/%s/%s/forks?org=%s",owner.login,name,org.getLogin()));
return org.getRepository(name);
// this API is asynchronous. we need to wait for a bit
for (int i=0; i<10; i++) {
GHRepository r = org.getRepository(name);
if (r!=null) return r;
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw (IOException)new InterruptedIOException().initCause(e);
}
}
throw new IOException(this+" was forked into "+org.getLogin()+" but can't find the new repository");
}
/**

View File

@@ -285,12 +285,12 @@ public class GitHub {
uc.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
uc.setRequestMethod(method);
uc.setRequestProperty("Accept-Encoding", "gzip");
if (method.equals("PUT")) {
uc.setDoOutput(true);
uc.setRequestProperty("Content-Length","0");
uc.getOutputStream().close();
}
uc.setRequestProperty("Accept-Encoding", "gzip");
return uc;
}

View File

@@ -31,6 +31,16 @@ import java.util.List;
* Unit test for simple App.
*/
public class AppTest extends TestCase {
public void testRepoCRUD() throws Exception {
GitHub hub = GitHub.connect();
GHRepository r = hub.createRepository("github-api-test", "a test repository", "http://github-api.kohsuke.org/", true);
r.enableIssueTracker(false);
r.enableDownloads(false);
r.enableWiki(false);
r.renameTo("github-api-test2");
hub.getMyself().getRepository("github-api-test2").delete();
}
public void testCredentialValid() throws IOException {
assertTrue(GitHub.connect().isCredentialValid());
assertFalse(GitHub.connect("totally","bogus").isCredentialValid());
@@ -253,11 +263,6 @@ public class AppTest extends TestCase {
gitHub.getUser("kohsuke").getRepository("test").renameTo("test2");
}
private void tryOrgFork(GitHub gitHub) throws IOException {
GHOrganization o = gitHub.getOrganization("HudsonLabs");
System.out.println(gitHub.getUser("rtyler").getRepository("memcache-ada").forkTo(o).getUrl());
}
private void tryTeamCreation(GitHub gitHub) throws IOException {
GHOrganization o = gitHub.getOrganization("HudsonLabs");
GHTeam t = o.createTeam("auto team", Permission.PUSH);