mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-13 15:50:09 +00:00
Compare commits
8 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a9ade667a | ||
|
|
057c32d410 | ||
|
|
33657c9c92 | ||
|
|
4c199256a5 | ||
|
|
9e62776905 | ||
|
|
9ba74b945d | ||
|
|
66656ce612 | ||
|
|
73a20ad829 |
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.24</version>
|
<version>1.26</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>
|
||||||
|
|||||||
@@ -43,15 +43,6 @@ public class GHOrganization extends GHPerson {
|
|||||||
return root.retrieveWithAuth("/organizations/"+login+"/teams",JsonTeams.class).toMap(this);
|
return root.retrieveWithAuth("/organizations/"+login+"/teams",JsonTeams.class).toMap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public GHRepository getRepository(String name) throws IOException {
|
|
||||||
try {
|
|
||||||
return root.retrieveWithAuth3("/repos/" + login + '/' + name, GHRepository.class).wrap(root);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publicizes the membership.
|
* Publicizes the membership.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public abstract class GHPerson {
|
|||||||
*/
|
*/
|
||||||
public GHRepository getRepository(String name) throws IOException {
|
public GHRepository getRepository(String name) throws IOException {
|
||||||
try {
|
try {
|
||||||
return root.retrieve3("/repos/" + login + '/' + name, GHRepository.class).wrap(root);
|
return root.retrieveWithAuth3("/repos/" + login + '/' + name, GHRepository.class).wrap(root);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/main/java/org/kohsuke/github/GHRateLimit.java
Normal file
21
src/main/java/org/kohsuke/github/GHRateLimit.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rate limit.
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
public class GHRateLimit {
|
||||||
|
/**
|
||||||
|
* Remaining calls that can be made.
|
||||||
|
*/
|
||||||
|
public int remaining;
|
||||||
|
/**
|
||||||
|
* Alotted API call per hour.
|
||||||
|
*/
|
||||||
|
public int limit;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return remaining+"/"+limit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -72,9 +72,16 @@ public class GHRepository {
|
|||||||
private String created_at, pushed_at;
|
private String created_at, pushed_at;
|
||||||
private Map<Integer,GHMilestone> milestones = new HashMap<Integer, GHMilestone>();
|
private Map<Integer,GHMilestone> milestones = new HashMap<Integer, GHMilestone>();
|
||||||
|
|
||||||
private String master_branch;
|
private String master_branch,language;
|
||||||
private Map<String,GHCommit> commits = new HashMap<String, GHCommit>();
|
private Map<String,GHCommit> commits = new HashMap<String, GHCommit>();
|
||||||
|
|
||||||
|
private GHRepoPermission permissions;
|
||||||
|
|
||||||
|
private static class GHRepoPermission {
|
||||||
|
boolean pull,push,admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
@@ -113,6 +120,25 @@ public class GHRepository {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasPullAccess() {
|
||||||
|
return permissions!=null && permissions.pull;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPushAccess() {
|
||||||
|
return permissions!=null && permissions.push;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAdminAccess() {
|
||||||
|
return permissions!=null && permissions.admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the primary programming language.
|
||||||
|
*/
|
||||||
|
public String getLanguage() {
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
public GHUser getOwner() throws IOException {
|
public GHUser getOwner() throws IOException {
|
||||||
return root.getUser(owner.login); // because 'owner' isn't fully populated
|
return root.getUser(owner.login); // because 'owner' isn't fully populated
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -288,7 +288,10 @@ public class GitHub {
|
|||||||
private HttpURLConnection setupConnection(String method, boolean withAuth, URL url) throws IOException {
|
private HttpURLConnection setupConnection(String method, boolean withAuth, URL url) throws IOException {
|
||||||
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
|
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
|
||||||
|
|
||||||
if (withAuth && this.oauthAccessToken == null)
|
// if the authentication is needed but no credential is given, try it anyway (so that some calls
|
||||||
|
// that do work with anonymous access in the reduced form should still work.)
|
||||||
|
// if OAuth token is present, it'll be set in the URL, so need to set the Authorization header
|
||||||
|
if (withAuth && encodedAuthorization!=null && this.oauthAccessToken == null)
|
||||||
uc.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
|
uc.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
|
||||||
|
|
||||||
uc.setRequestMethod(method);
|
uc.setRequestMethod(method);
|
||||||
@@ -355,6 +358,13 @@ public class GitHub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current rate limit.
|
||||||
|
*/
|
||||||
|
public GHRateLimit getRateLimit() throws IOException {
|
||||||
|
return retrieveWithAuth3("/rate_limit",JsonRateLimit.class).rate;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link GHUser} that represents yourself.
|
* Gets the {@link GHUser} that represents yourself.
|
||||||
*/
|
*/
|
||||||
|
|||||||
8
src/main/java/org/kohsuke/github/JsonRateLimit.java
Normal file
8
src/main/java/org/kohsuke/github/JsonRateLimit.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
class JsonRateLimit {
|
||||||
|
GHRateLimit rate;
|
||||||
|
}
|
||||||
@@ -36,6 +36,10 @@ public class AppTest extends TestCase {
|
|||||||
assertFalse(GitHub.connect("totally","bogus").isCredentialValid());
|
assertFalse(GitHub.connect("totally","bogus").isCredentialValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testRateLimit() throws IOException {
|
||||||
|
System.out.println(GitHub.connect().getRateLimit());
|
||||||
|
}
|
||||||
|
|
||||||
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");
|
||||||
@@ -43,6 +47,15 @@ public class AppTest extends TestCase {
|
|||||||
r.getPullRequest(1);
|
r.getPullRequest(1);
|
||||||
r.getPullRequests(GHIssueState.OPEN);
|
r.getPullRequests(GHIssueState.OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testRepoPermissions() throws Exception {
|
||||||
|
GitHub gh = GitHub.connect();
|
||||||
|
GHRepository r = gh.getOrganization("jenkinsci").getRepository("jenkins");
|
||||||
|
assertTrue(r.hasPullAccess());
|
||||||
|
|
||||||
|
r = gh.getOrganization("github").getRepository("tire");
|
||||||
|
assertFalse(r.hasAdminAccess());
|
||||||
|
}
|
||||||
|
|
||||||
public void tryGetMyself() throws Exception {
|
public void tryGetMyself() throws Exception {
|
||||||
GitHub hub = GitHub.connect();
|
GitHub hub = GitHub.connect();
|
||||||
|
|||||||
Reference in New Issue
Block a user