Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 20e68d5

Browse filesBrowse files
committed
Merge pull request hub4j#283
2 parents d8f4bc7 + 2d3557e commit 20e68d5
Copy full SHA for 20e68d5

File tree

Expand file treeCollapse file tree

8 files changed

+56
-31
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+56
-31
lines changed

‎src/main/java/org/kohsuke/github/GHCommitPointer.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHCommitPointer.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public class GHCommitPointer {
3939
* This points to the user who owns
4040
* the {@link #getRepository()}.
4141
*/
42-
public GHUser getUser() {
42+
public GHUser getUser() throws IOException {
43+
if (user != null) return user.root.intern(user);
4344
return user;
4445
}
4546

‎src/main/java/org/kohsuke/github/GHCommitStatus.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHCommitStatus.java
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.kohsuke.github;
22

3+
import java.io.IOException;
34
import java.net.URL;
45

56
/**
@@ -45,8 +46,8 @@ public String getDescription() {
4546
return description;
4647
}
4748

48-
public GHUser getCreator() {
49-
return creator;
49+
public GHUser getCreator() throws IOException {
50+
return root.intern(creator);
5051
}
5152

5253
public String getContext() {

‎src/main/java/org/kohsuke/github/GHDeployment.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHDeployment.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.kohsuke.github;
22

3-
3+
import java.io.IOException;
44
import java.net.URL;
55

66
public class GHDeployment extends GHObject {
@@ -41,8 +41,8 @@ public String getPayload() {
4141
public String getEnvironment() {
4242
return environment;
4343
}
44-
public GHUser getCreator() {
45-
return creator;
44+
public GHUser getCreator() throws IOException {
45+
return root.intern(creator);
4646
}
4747
public String getRef() {
4848
return ref;

‎src/main/java/org/kohsuke/github/GHGist.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHGist.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class GHGist extends GHObject {
3838
/**
3939
* User that owns this Gist.
4040
*/
41-
public GHUser getOwner() {
42-
return owner;
41+
public GHUser getOwner() throws IOException {
42+
return root.intern(owner);
4343
}
4444

4545
public String getForksUrl() {

‎src/main/java/org/kohsuke/github/GHIssue.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHIssue.java
+13-9Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ protected String getIssuesApiRoute() {
288288
return "/repos/"+owner.getOwnerName()+"/"+owner.getName()+"/issues/"+number;
289289
}
290290

291-
public GHUser getAssignee() {
292-
return assignee;
291+
public GHUser getAssignee() throws IOException {
292+
return root.intern(assignee);
293293
}
294294

295295
public List<GHUser> getAssignees() {
@@ -299,8 +299,8 @@ public List<GHUser> getAssignees() {
299299
/**
300300
* User who submitted the issue.
301301
*/
302-
public GHUser getUser() {
303-
return user;
302+
public GHUser getUser() throws IOException {
303+
return root.intern(user);
304304
}
305305

306306
/**
@@ -311,12 +311,16 @@ public GHUser getUser() {
311311
* even for an issue that's already closed. See
312312
* https://github.com/kohsuke/github-api/issues/60.
313313
*/
314-
public GHUser getClosedBy() {
314+
public GHUser getClosedBy() throws IOException {
315315
if(!"closed".equals(state)) return null;
316-
if(closed_by != null) return closed_by;
317-
318-
//TODO closed_by = owner.getIssue(number).getClosed_by();
319-
return closed_by;
316+
317+
//TODO
318+
/*
319+
if (closed_by==null) {
320+
closed_by = owner.getIssue(number).getClosed_by();
321+
}
322+
*/
323+
return root.intern(closed_by);
320324
}
321325

322326
public int getCommentsCount(){

‎src/main/java/org/kohsuke/github/GHMilestone.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHMilestone.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public GHRepository getOwner() {
2727
return owner;
2828
}
2929

30-
public GHUser getCreator() {
31-
return creator;
30+
public GHUser getCreator() throws IOException {
31+
return root.intern(creator);
3232
}
3333

3434
public Date getDueOn() {

‎src/main/java/org/kohsuke/github/GHPullRequest.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHPullRequest.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public String getMergeCommitSha() throws IOException {
206206
* Depending on the original API call where this object is created, it may not contain everything.
207207
*/
208208
private void populate() throws IOException {
209-
if (merged_by!=null) return; // already populated
209+
if (mergeable_state!=null) return; // already populated
210210
if (root.isOffline()) {
211211
return; // cannot populate, will have to live with what we have
212212
}

‎src/main/java/org/kohsuke/github/GitHub.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GitHub.java
+30-11Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
import java.util.Map;
5454
import java.util.Set;
5555
import java.util.TimeZone;
56+
import java.util.concurrent.ConcurrentHashMap;
57+
import java.util.concurrent.ConcurrentMap;
5658
import java.util.logging.Logger;
5759

5860
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.*;
@@ -79,9 +81,10 @@ public class GitHub {
7981
*/
8082
/*package*/ final String encodedAuthorization;
8183

82-
private final Map<String,GHUser> users = new Hashtable<String, GHUser>();
83-
private final Map<String,GHOrganization> orgs = new Hashtable<String, GHOrganization>();
84-
84+
private final ConcurrentMap<String,GHUser> users;
85+
private final ConcurrentMap<String,GHOrganization> orgs;
86+
// Cache of myself object.
87+
private GHMyself myself;
8588
private final String apiUrl;
8689

8790
/*package*/ final RateLimitHandler rateLimitHandler;
@@ -146,6 +149,8 @@ public class GitHub {
146149
}
147150
}
148151

152+
users = new ConcurrentHashMap<String, GHUser>();
153+
orgs = new ConcurrentHashMap<String, GHOrganization>();
149154
this.rateLimitHandler = rateLimitHandler;
150155
this.abuseLimitHandler = abuseLimitHandler;
151156

@@ -264,7 +269,7 @@ public String getApiUrl() {
264269
/**
265270
* Sets the custom connector used to make requests to GitHub.
266271
*/
267-
public void setConnector(HttpConnector connector) {
272+
public synchronized void setConnector(HttpConnector connector) {
268273
this.connector = connector;
269274
}
270275

@@ -357,13 +362,15 @@ public GHRateLimit rateLimit() throws IOException {
357362
@WithBridgeMethods(GHUser.class)
358363
public GHMyself getMyself() throws IOException {
359364
requireCredential();
365+
synchronized (this) {
366+
if (this.myself != null) return myself;
367+
368+
GHMyself u = retrieve().to("/user", GHMyself.class);
360369

361-
GHMyself u = retrieve().to("/user", GHMyself.class);
362-
363-
u.root = this;
364-
users.put(u.getLogin(), u);
365-
366-
return u;
370+
u.root = this;
371+
this.myself = u;
372+
return u;
373+
}
367374
}
368375

369376
/**
@@ -379,7 +386,7 @@ public GHUser getUser(String login) throws IOException {
379386
return u;
380387
}
381388

382-
389+
383390
/**
384391
* clears all cached data in order for external changes (modifications and del
385392
*/
@@ -641,6 +648,18 @@ public boolean isCredentialValid() throws IOException {
641648
}
642649
}
643650

651+
/*package*/ GHUser intern(GHUser user) throws IOException {
652+
if (user==null) return user;
653+
654+
// if we already have this user in our map, use it
655+
GHUser u = users.get(user.getLogin());
656+
if (u!=null) return u;
657+
658+
// if not, remember this new user
659+
users.putIfAbsent(user.getLogin(),user);
660+
return user;
661+
}
662+
644663
private static class GHApiInfo {
645664
private String rate_limit_url;
646665

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.