mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-13 15:50:09 +00:00
Compare commits
16 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db845850b2 | ||
|
|
d516597659 | ||
|
|
3af5a8145a | ||
|
|
31bebd4a7a | ||
|
|
ccb87258b0 | ||
|
|
2ab71e88bd | ||
|
|
78bd7585bb | ||
|
|
92cc81d9b8 | ||
|
|
97a1c741de | ||
|
|
077d693959 | ||
|
|
94831fc10a | ||
|
|
1f298a88b0 | ||
|
|
311180d12e | ||
|
|
0efb206881 | ||
|
|
a58a5b56b2 | ||
|
|
b9764c0a44 |
6
pom.xml
6
pom.xml
@@ -3,11 +3,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.kohsuke</groupId>
|
<groupId>org.kohsuke</groupId>
|
||||||
<artifactId>pom</artifactId>
|
<artifactId>pom</artifactId>
|
||||||
<version>9</version>
|
<version>10</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.57</version>
|
<version>1.58</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>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
||||||
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
||||||
<url>http://${project.artifactId}.kohsuke.org/</url>
|
<url>http://${project.artifactId}.kohsuke.org/</url>
|
||||||
<tag>HEAD</tag>
|
<tag>github-api-1.58</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ public enum GHEvent {
|
|||||||
COMMIT_COMMENT,
|
COMMIT_COMMENT,
|
||||||
CREATE,
|
CREATE,
|
||||||
DELETE,
|
DELETE,
|
||||||
|
DEPLOYMENT,
|
||||||
|
DEPLOYMENT_STATUS,
|
||||||
DOWNLOAD,
|
DOWNLOAD,
|
||||||
FOLLOW,
|
FOLLOW,
|
||||||
FORK,
|
FORK,
|
||||||
@@ -25,6 +27,8 @@ public enum GHEvent {
|
|||||||
PULL_REQUEST,
|
PULL_REQUEST,
|
||||||
PULL_REQUEST_REVIEW_COMMENT,
|
PULL_REQUEST_REVIEW_COMMENT,
|
||||||
PUSH,
|
PUSH,
|
||||||
|
RELEASE,
|
||||||
|
STATUS,
|
||||||
TEAM_ADD,
|
TEAM_ADD,
|
||||||
WATCH
|
WATCH
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ public class GHPullRequest extends GHIssue {
|
|||||||
return new PagedIterable<GHPullRequestCommitDetail>() {
|
return new PagedIterable<GHPullRequestCommitDetail>() {
|
||||||
public PagedIterator<GHPullRequestCommitDetail> iterator() {
|
public PagedIterator<GHPullRequestCommitDetail> iterator() {
|
||||||
return new PagedIterator<GHPullRequestCommitDetail>(root.retrieve().asIterator(
|
return new PagedIterator<GHPullRequestCommitDetail>(root.retrieve().asIterator(
|
||||||
String.format("%s/commits", getApiURL().getPath()),
|
String.format("%s/commits", getApiURL()),
|
||||||
GHPullRequestCommitDetail[].class)) {
|
GHPullRequestCommitDetail[].class)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHPullRequestCommitDetail[] page) {
|
protected void wrapUp(GHPullRequestCommitDetail[] page) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,6 +9,7 @@ import java.net.URL;
|
|||||||
* @author Michael Clarke
|
* @author Michael Clarke
|
||||||
*/
|
*/
|
||||||
public class GHRef {
|
public class GHRef {
|
||||||
|
/*package almost final*/ GitHub root;
|
||||||
|
|
||||||
private String ref, url;
|
private String ref, url;
|
||||||
private GHObject object;
|
private GHObject object;
|
||||||
@@ -33,6 +35,48 @@ public class GHRef {
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates this ref to the specified commit.
|
||||||
|
*
|
||||||
|
* @param sha
|
||||||
|
* The SHA1 value to set this reference to
|
||||||
|
*/
|
||||||
|
public void updateTo(String sha) throws IOException {
|
||||||
|
updateTo(sha, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates this ref to the specified commit.
|
||||||
|
*
|
||||||
|
* @param sha
|
||||||
|
* The SHA1 value to set this reference to
|
||||||
|
* @param force
|
||||||
|
* Whether or not to force this ref update.
|
||||||
|
*/
|
||||||
|
public void updateTo(String sha, Boolean force) throws IOException {
|
||||||
|
new Requester(root)
|
||||||
|
.with("sha", sha).with("force", force).method("PATCH").to(url, GHRef.class).wrap(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes this ref from the repository using the GitHub API.
|
||||||
|
*/
|
||||||
|
public void delete() throws IOException {
|
||||||
|
new Requester(root).method("DELETE").to(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*package*/ GHRef wrap(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*package*/ static GHRef[] wrap(GHRef[] in, GitHub root) {
|
||||||
|
for (GHRef r : in) {
|
||||||
|
r.wrap(root);
|
||||||
|
}
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class GHObject {
|
public static class GHObject {
|
||||||
private String type, sha, url;
|
private String type, sha, url;
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ import static java.util.Arrays.*;
|
|||||||
public class GHRepository {
|
public class GHRepository {
|
||||||
/*package almost final*/ GitHub root;
|
/*package almost final*/ GitHub root;
|
||||||
|
|
||||||
private String description, homepage, name;
|
private String description, homepage, name, full_name;
|
||||||
private String url; // this is the API url
|
private String url; // this is the API url
|
||||||
private String html_url; // this is the UI
|
private String html_url; // this is the UI
|
||||||
private String git_url, ssh_url, clone_url, svn_url;
|
private String git_url, ssh_url, clone_url, svn_url;
|
||||||
@@ -131,6 +131,13 @@ public class GHRepository {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full repository name including the owner or organization. For example 'jenkinsci/jenkins' in case of http://github.com/jenkinsci/jenkins
|
||||||
|
*/
|
||||||
|
public String getFullName() {
|
||||||
|
return full_name;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasPullAccess() {
|
public boolean hasPullAccess() {
|
||||||
return permissions!=null && permissions.pull;
|
return permissions!=null && permissions.pull;
|
||||||
}
|
}
|
||||||
@@ -206,7 +213,7 @@ public class GHRepository {
|
|||||||
*/
|
*/
|
||||||
public GHRef createRef(String name, String sha) throws IOException {
|
public GHRef createRef(String name, String sha) throws IOException {
|
||||||
return new Requester(root)
|
return new Requester(root)
|
||||||
.with("ref", name).with("sha", sha).method("POST").to(getApiTailUrl("git/refs"), GHRef.class);
|
.with("ref", name).with("sha", sha).method("POST").to(getApiTailUrl("git/refs"), GHRef.class).wrap(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -579,17 +586,17 @@ public class GHRepository {
|
|||||||
* @throws IOException on failure communicating with GitHub
|
* @throws IOException on failure communicating with GitHub
|
||||||
*/
|
*/
|
||||||
public GHRef[] getRefs() throws IOException {
|
public GHRef[] getRefs() throws IOException {
|
||||||
return root.retrieve().to(String.format("/repos/%s/%s/git/refs", owner.login, name), GHRef[].class);
|
return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs", owner.login, name), GHRef[].class),root);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrienved all refs of the given type for the current GitHub repository.
|
* Retrieves all refs of the given type for the current GitHub repository.
|
||||||
* @param refType the type of reg to search for e.g. <tt>tags</tt> or <tt>commits</tt>
|
* @param refType the type of reg to search for e.g. <tt>tags</tt> or <tt>commits</tt>
|
||||||
* @return an array of all refs matching the request type
|
* @return an array of all refs matching the request type
|
||||||
* @throws IOException on failure communicating with GitHub, potentially due to an invalid ref type being requested
|
* @throws IOException on failure communicating with GitHub, potentially due to an invalid ref type being requested
|
||||||
*/
|
*/
|
||||||
public GHRef[] getRefs(String refType) 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);
|
return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refType), GHRef[].class),root);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Retrive a ref of the given type for the current GitHub repository.
|
* Retrive a ref of the given type for the current GitHub repository.
|
||||||
@@ -602,7 +609,7 @@ public class GHRepository {
|
|||||||
* invalid ref type being requested
|
* invalid ref type being requested
|
||||||
*/
|
*/
|
||||||
public GHRef getRef(String refName) throws IOException {
|
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);
|
return root.retrieve().to(String.format("/repos/%s/%s/git/refs/%s", owner.login, name, refName), GHRef.class).wrap(root);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Gets a commit object in this repository.
|
* Gets a commit object in this repository.
|
||||||
|
|||||||
@@ -283,6 +283,15 @@ public class GitHub {
|
|||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clears all cached data in order for external changes (modifications and del
|
||||||
|
*/
|
||||||
|
public void refreshCache() {
|
||||||
|
users.clear();
|
||||||
|
orgs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interns the given {@link GHUser}.
|
* Interns the given {@link GHUser}.
|
||||||
*/
|
*/
|
||||||
@@ -357,7 +366,6 @@ public class GitHub {
|
|||||||
* Public events visible to you. Equivalent of what's displayed on https://github.com/
|
* Public events visible to you. Equivalent of what's displayed on https://github.com/
|
||||||
*/
|
*/
|
||||||
public List<GHEventInfo> getEvents() throws IOException {
|
public List<GHEventInfo> getEvents() throws IOException {
|
||||||
// TODO: pagination
|
|
||||||
GHEventInfo[] events = retrieve().to("/events", GHEventInfo[].class);
|
GHEventInfo[] events = retrieve().to("/events", GHEventInfo[].class);
|
||||||
for (GHEventInfo e : events)
|
for (GHEventInfo e : events)
|
||||||
e.wrapUp(this);
|
e.wrapUp(this);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.InterruptedIOException;
|
import java.io.InterruptedIOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@@ -47,10 +48,14 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A builder pattern for making HTTP call and parsing its output.
|
* A builder pattern for making HTTP call and parsing its output.
|
||||||
*
|
*
|
||||||
@@ -177,7 +182,26 @@ class Requester {
|
|||||||
buildRequest(uc);
|
buildRequest(uc);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return parse(uc,type,instance);
|
T result = parse(uc, type, instance);
|
||||||
|
if (type != null && type.isArray()) { // we might have to loop for pagination - done through recursion
|
||||||
|
final String links = uc.getHeaderField("link");
|
||||||
|
if (links != null && links.contains("rel=\"next\"")) {
|
||||||
|
Pattern nextLinkPattern = Pattern.compile(".*<(.*)>; rel=\"next\"");
|
||||||
|
Matcher nextLinkMatcher = nextLinkPattern.matcher(links);
|
||||||
|
if (nextLinkMatcher.find()) {
|
||||||
|
final String link = nextLinkMatcher.group(1);
|
||||||
|
T nextResult = _to(link, type, instance);
|
||||||
|
|
||||||
|
final int resultLength = Array.getLength(result);
|
||||||
|
final int nextResultLength = Array.getLength(nextResult);
|
||||||
|
T concatResult = (T) Array.newInstance(type.getComponentType(), resultLength + nextResultLength);
|
||||||
|
System.arraycopy(result, 0, concatResult, 0, resultLength);
|
||||||
|
System.arraycopy(nextResult, 0, concatResult, resultLength, nextResultLength);
|
||||||
|
result = concatResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
handleApiError(e,uc);
|
handleApiError(e,uc);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user