mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-14 15:50:05 +00:00
Compare commits
13 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40a8c110bf | ||
|
|
c9cd0a4d1f | ||
|
|
45eae77f8f | ||
|
|
926202900c | ||
|
|
21aa669503 | ||
|
|
dee28e7a7a | ||
|
|
c8f46a3666 | ||
|
|
ba7fe10a08 | ||
|
|
9e9db72878 | ||
|
|
69a87e2ab7 | ||
|
|
8ec2686e72 | ||
|
|
d034ca4d1f | ||
|
|
61cf71fd67 |
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.27</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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ public abstract class GHPerson {
|
|||||||
protected int id;
|
protected int id;
|
||||||
protected String gravatar_id; // appears in V3 as well but presumably subsumed by avatar_url?
|
protected String gravatar_id; // appears in V3 as well but presumably subsumed by avatar_url?
|
||||||
|
|
||||||
// V2
|
|
||||||
protected int public_gist_count,public_repo_count,followers_count,following_count;
|
|
||||||
|
|
||||||
// V3
|
// V3
|
||||||
protected String avatar_url,html_url;
|
protected String avatar_url,html_url;
|
||||||
protected int followers,following,public_repos,public_gists;
|
protected int followers,following,public_repos,public_gists;
|
||||||
@@ -163,15 +160,15 @@ public abstract class GHPerson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getPublicGistCount() {
|
public int getPublicGistCount() {
|
||||||
return Math.max(public_gist_count,public_gists);
|
return public_gists;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPublicRepoCount() {
|
public int getPublicRepoCount() {
|
||||||
return Math.max(public_repo_count,public_repos);
|
return public_repos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFollowingCount() {
|
public int getFollowingCount() {
|
||||||
return Math.max(following_count,following);
|
return following;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,7 +179,7 @@ public abstract class GHPerson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getFollowersCount() {
|
public int getFollowersCount() {
|
||||||
return Math.max(followers_count,followers);
|
return followers;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,11 +415,18 @@ public class GitHub {
|
|||||||
return getUser(tokens[0]).getRepository(tokens[1]);
|
return getUser(tokens[0]).getRepository(tokens[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns a shallowly populated organizations.
|
||||||
|
*
|
||||||
|
* To retrieve full organization details, you need to call {@link #getOrganization(String)}
|
||||||
|
* TODO: make this automatic.
|
||||||
|
*/
|
||||||
public Map<String, GHOrganization> getMyOrganizations() throws IOException {
|
public Map<String, GHOrganization> getMyOrganizations() throws IOException {
|
||||||
GHOrganization[] orgs = retrieveWithAuth("/user/orgs", GHOrganization[].class);
|
GHOrganization[] orgs = retrieveWithAuth("/user/orgs", GHOrganization[].class);
|
||||||
Map<String, GHOrganization> r = new HashMap<String, GHOrganization>();
|
Map<String, GHOrganization> r = new HashMap<String, GHOrganization>();
|
||||||
for (GHOrganization o : orgs) {
|
for (GHOrganization o : orgs) {
|
||||||
r.put(o.name,o.wrapUp(this));
|
// don't put 'o' into orgs because they are shallow
|
||||||
|
r.put(o.getLogin(),o.wrapUp(this));
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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());
|
||||||
@@ -40,6 +50,12 @@ public class AppTest extends TestCase {
|
|||||||
System.out.println(GitHub.connect().getRateLimit());
|
System.out.println(GitHub.connect().getRateLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testMyOrganizations() throws IOException {
|
||||||
|
Map<String, GHOrganization> org = GitHub.connect().getMyOrganizations();
|
||||||
|
assertFalse(org.keySet().contains(null));
|
||||||
|
System.out.println(org);
|
||||||
|
}
|
||||||
|
|
||||||
public void testFetchPullRequest() throws Exception {
|
public void testFetchPullRequest() throws Exception {
|
||||||
GitHub gh = GitHub.connect();
|
GitHub gh = GitHub.connect();
|
||||||
GHRepository r = gh.getOrganization("jenkinsci").getRepository("jenkins");
|
GHRepository r = gh.getOrganization("jenkinsci").getRepository("jenkins");
|
||||||
@@ -247,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