diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 136daf0df7..5404b1f309 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -283,6 +283,15 @@ public GHUser getUser(String login) throws IOException { 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}. */ @@ -357,7 +366,6 @@ public Map> getMyTeams() throws IOException { * Public events visible to you. Equivalent of what's displayed on https://github.com/ */ public List getEvents() throws IOException { - // TODO: pagination GHEventInfo[] events = retrieve().to("/events", GHEventInfo[].class); for (GHEventInfo e : events) e.wrapUp(this); diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 10cb2bfb74..c15485d305 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -32,6 +32,7 @@ import java.io.InterruptedIOException; import java.io.Reader; import java.io.UnsupportedEncodingException; +import java.lang.reflect.Array; import java.lang.reflect.Field; import java.net.HttpURLConnection; import java.net.MalformedURLException; @@ -47,10 +48,14 @@ import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; import org.apache.commons.io.IOUtils; +import javax.net.ssl.HttpsURLConnection; + /** * A builder pattern for making HTTP call and parsing its output. * @@ -177,7 +182,26 @@ private T _to(String tailApiUrl, Class type, T instance) throws IOExcepti buildRequest(uc); 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) { handleApiError(e,uc); }