diff --git a/src/main/java/org/kohsuke/github/GHCommitPointer.java b/src/main/java/org/kohsuke/github/GHCommitPointer.java index b9716366b5..6b3f414f43 100644 --- a/src/main/java/org/kohsuke/github/GHCommitPointer.java +++ b/src/main/java/org/kohsuke/github/GHCommitPointer.java @@ -39,7 +39,8 @@ public class GHCommitPointer { * This points to the user who owns * the {@link #getRepository()}. */ - public GHUser getUser() { + public GHUser getUser() throws IOException { + if (user != null) return user.root.getUser(user.getLogin()); return user; } diff --git a/src/main/java/org/kohsuke/github/GHCommitStatus.java b/src/main/java/org/kohsuke/github/GHCommitStatus.java index 7b876fc5a0..f71be99622 100644 --- a/src/main/java/org/kohsuke/github/GHCommitStatus.java +++ b/src/main/java/org/kohsuke/github/GHCommitStatus.java @@ -1,5 +1,6 @@ package org.kohsuke.github; +import java.io.IOException; import java.net.URL; /** @@ -45,7 +46,8 @@ public String getDescription() { return description; } - public GHUser getCreator() { + public GHUser getCreator() throws IOException { + if (creator != null) return creator.root.getUser(creator.getLogin()); return creator; } diff --git a/src/main/java/org/kohsuke/github/GHDeployment.java b/src/main/java/org/kohsuke/github/GHDeployment.java index 51a7843d0b..ff8b4d6afc 100644 --- a/src/main/java/org/kohsuke/github/GHDeployment.java +++ b/src/main/java/org/kohsuke/github/GHDeployment.java @@ -1,6 +1,6 @@ package org.kohsuke.github; - +import java.io.IOException; import java.net.URL; public class GHDeployment extends GHObject { @@ -41,7 +41,8 @@ public String getPayload() { public String getEnvironment() { return environment; } - public GHUser getCreator() { + public GHUser getCreator() throws IOException { + if(creator != null) return root.getUser(creator.getLogin()); return creator; } public String getRef() { diff --git a/src/main/java/org/kohsuke/github/GHGist.java b/src/main/java/org/kohsuke/github/GHGist.java index eb105b40c6..e0954175d0 100644 --- a/src/main/java/org/kohsuke/github/GHGist.java +++ b/src/main/java/org/kohsuke/github/GHGist.java @@ -38,8 +38,8 @@ public class GHGist extends GHObject { /** * User that owns this Gist. */ - public GHUser getOwner() { - return owner; + public GHUser getOwner() throws IOException { + return root.getUser(owner.getLogin()); } public String getForksUrl() { diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 849d4831ff..9a3b31f11b 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -288,7 +288,8 @@ protected String getIssuesApiRoute() { return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/issues/"+number; } - public GHUser getAssignee() { + public GHUser getAssignee() throws IOException { + if (assignee != null) return owner.root.getUser(assignee.getLogin()); return assignee; } @@ -299,8 +300,8 @@ public List getAssignees() { /** * User who submitted the issue. */ - public GHUser getUser() { - return user; + public GHUser getUser() throws IOException { + return owner.root.getUser(user.getLogin()); } /** @@ -311,9 +312,9 @@ public GHUser getUser() { * even for an issue that's already closed. See * https://github.com/kohsuke/github-api/issues/60. */ - public GHUser getClosedBy() { + public GHUser getClosedBy() throws IOException { if(!"closed".equals(state)) return null; - if(closed_by != null) return closed_by; + if(closed_by != null) return owner.root.getUser(closed_by.getLogin());; //TODO closed_by = owner.getIssue(number).getClosed_by(); return closed_by; diff --git a/src/main/java/org/kohsuke/github/GHMilestone.java b/src/main/java/org/kohsuke/github/GHMilestone.java index 48f8364bbf..950dea2574 100644 --- a/src/main/java/org/kohsuke/github/GHMilestone.java +++ b/src/main/java/org/kohsuke/github/GHMilestone.java @@ -27,8 +27,8 @@ public GHRepository getOwner() { return owner; } - public GHUser getCreator() { - return creator; + public GHUser getCreator() throws IOException { + return root.getUser(creator.getLogin()); } public Date getDueOn() { diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 04898039bc..fdc0d9d420 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -200,7 +200,7 @@ public String getMergeCommitSha() throws IOException { * Depending on the original API call where this object is created, it may not contain everything. */ private void populate() throws IOException { - if (merged_by!=null) return; // already populated + if (mergeable_state!=null) return; // already populated if (root.isOffline()) { return; // cannot populate, will have to live with what we have } diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 896fb36c63..bde74b1262 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -47,6 +47,7 @@ import java.util.Map; import java.util.Set; import java.util.TimeZone; +import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; @@ -79,9 +80,10 @@ public class GitHub { */ /*package*/ final String encodedAuthorization; - private final Map users = new Hashtable(); - private final Map orgs = new Hashtable(); - + private final Map users; + private final Map orgs; + // Cache of myself object. + private GHMyself myself; private final String apiUrl; /*package*/ final RateLimitHandler rateLimitHandler; @@ -146,6 +148,8 @@ public class GitHub { } } + users = new ConcurrentHashMap(); + orgs = new ConcurrentHashMap(); this.rateLimitHandler = rateLimitHandler; this.abuseLimitHandler = abuseLimitHandler; @@ -264,7 +268,7 @@ public String getApiUrl() { /** * Sets the custom connector used to make requests to GitHub. */ - public void setConnector(HttpConnector connector) { + public synchronized void setConnector(HttpConnector connector) { this.connector = connector; } @@ -357,13 +361,15 @@ public GHRateLimit rateLimit() throws IOException { @WithBridgeMethods(GHUser.class) public GHMyself getMyself() throws IOException { requireCredential(); + synchronized (this) { + if (this.myself != null) return myself; + + GHMyself u = retrieve().to("/user", GHMyself.class); - GHMyself u = retrieve().to("/user", GHMyself.class); - - u.root = this; - users.put(u.getLogin(), u); - - return u; + u.root = this; + this.myself = u; + return u; + } } /** @@ -379,7 +385,7 @@ public GHUser getUser(String login) throws IOException { return u; } - + /** * clears all cached data in order for external changes (modifications and del */