mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-13 15:50:09 +00:00
Compare commits
9 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40a8c110bf | ||
|
|
c9cd0a4d1f | ||
|
|
45eae77f8f | ||
|
|
926202900c | ||
|
|
21aa669503 | ||
|
|
dee28e7a7a | ||
|
|
c8f46a3666 | ||
|
|
ba7fe10a08 | ||
|
|
9e9db72878 |
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.28</version>
|
<version>1.29</version>
|
||||||
<name>GitHub API for Java</name>
|
<name>GitHub API for Java</name>
|
||||||
<url>http://github-api.kohsuke.org/</url>
|
<url>http://github-api.kohsuke.org/</url>
|
||||||
<description>GitHub API for Java</description>
|
<description>GitHub API for Java</description>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class GHOrganization extends GHPerson {
|
|||||||
GHTeam[] teams = root.retrieveWithAuth("/orgs/" + login + "/teams", GHTeam[].class);
|
GHTeam[] teams = root.retrieveWithAuth("/orgs/" + login + "/teams", GHTeam[].class);
|
||||||
Map<String,GHTeam> r = new TreeMap<String, GHTeam>();
|
Map<String,GHTeam> r = new TreeMap<String, GHTeam>();
|
||||||
for (GHTeam t : teams) {
|
for (GHTeam t : teams) {
|
||||||
r.put(t.getName(),t);
|
r.put(t.getName(),t.wrapUp(this));
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
|||||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InterruptedIOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.AbstractSet;
|
import java.util.AbstractSet;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -269,8 +270,11 @@ public class GHRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void edit(String key, String value) throws IOException {
|
private void edit(String key, String value) throws IOException {
|
||||||
new Poster(root).withCredential().with(key,value)
|
Poster poster = new Poster(root).withCredential();
|
||||||
.to("/repos/" + owner.login + "/" + name,null,"PATCH");
|
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.
|
* Deletes this repository.
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
throw new UnsupportedOperationException(); // doesn't appear to be available in V3
|
new Poster(root).withCredential().to("/repos/" + owner.login +"/"+name, null, "DELETE");
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -336,7 +335,18 @@ public class GHRepository {
|
|||||||
*/
|
*/
|
||||||
public GHRepository forkTo(GHOrganization org) throws IOException {
|
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()));
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -285,12 +285,12 @@ public class GitHub {
|
|||||||
uc.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
|
uc.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
|
||||||
|
|
||||||
uc.setRequestMethod(method);
|
uc.setRequestMethod(method);
|
||||||
|
uc.setRequestProperty("Accept-Encoding", "gzip");
|
||||||
if (method.equals("PUT")) {
|
if (method.equals("PUT")) {
|
||||||
uc.setDoOutput(true);
|
uc.setDoOutput(true);
|
||||||
uc.setRequestProperty("Content-Length","0");
|
uc.setRequestProperty("Content-Length","0");
|
||||||
uc.getOutputStream().close();
|
uc.getOutputStream().close();
|
||||||
}
|
}
|
||||||
uc.setRequestProperty("Accept-Encoding", "gzip");
|
|
||||||
return uc;
|
return uc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,16 @@ import java.util.List;
|
|||||||
* Unit test for simple App.
|
* Unit test for simple App.
|
||||||
*/
|
*/
|
||||||
public class AppTest extends TestCase {
|
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 {
|
public void testCredentialValid() throws IOException {
|
||||||
assertTrue(GitHub.connect().isCredentialValid());
|
assertTrue(GitHub.connect().isCredentialValid());
|
||||||
assertFalse(GitHub.connect("totally","bogus").isCredentialValid());
|
assertFalse(GitHub.connect("totally","bogus").isCredentialValid());
|
||||||
@@ -253,11 +263,6 @@ public class AppTest extends TestCase {
|
|||||||
gitHub.getUser("kohsuke").getRepository("test").renameTo("test2");
|
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 {
|
private void tryTeamCreation(GitHub gitHub) throws IOException {
|
||||||
GHOrganization o = gitHub.getOrganization("HudsonLabs");
|
GHOrganization o = gitHub.getOrganization("HudsonLabs");
|
||||||
GHTeam t = o.createTeam("auto team", Permission.PUSH);
|
GHTeam t = o.createTeam("auto team", Permission.PUSH);
|
||||||
|
|||||||
Reference in New Issue
Block a user