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 f9006af

Browse filesBrowse files
authored
Merge branch 'master' into complete-checks-api
2 parents 57f9475 + c11c06b commit f9006af
Copy full SHA for f9006af

File tree

Expand file treeCollapse file tree

9 files changed

+106
-57
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+106
-57
lines changed

‎pom.xml

Copy file name to clipboardExpand all lines: pom.xml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@
495495
<dependency>
496496
<groupId>org.mockito</groupId>
497497
<artifactId>mockito-core</artifactId>
498-
<version>3.3.0</version>
498+
<version>3.3.1</version>
499499
<scope>test</scope>
500500
</dependency>
501501
<dependency>
@@ -507,7 +507,7 @@
507507
<dependency>
508508
<groupId>com.github.tomakehurst</groupId>
509509
<artifactId>wiremock-jre8-standalone</artifactId>
510-
<version>2.26.0</version>
510+
<version>2.26.1</version>
511511
<scope>test</scope>
512512
</dependency>
513513
<dependency>

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHEventInfo.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public GHOrganization getOrganization() throws IOException {
142142
* if payload cannot be parsed
143143
*/
144144
public <T extends GHEventPayload> T getPayload(Class<T> type) throws IOException {
145-
T v = GitHubClient.getMappingObjectReader().readValue(payload.traverse(), type);
145+
T v = GitHubClient.getMappingObjectReader(root).readValue(payload.traverse(), type);
146146
v.wrapUp(root);
147147
return v;
148148
}

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

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

3+
import com.fasterxml.jackson.annotation.JacksonInject;
4+
import com.fasterxml.jackson.annotation.JsonCreator;
35
import com.fasterxml.jackson.annotation.JsonProperty;
46
import org.apache.commons.lang3.StringUtils;
57

68
import java.io.IOException;
79
import java.net.URL;
810
import java.util.Collections;
9-
import java.util.HashMap;
1011
import java.util.Map;
1112
import java.util.Map.Entry;
1213

@@ -19,8 +20,9 @@
1920
* @see <a href="https://developer.github.com/v3/gists/">documentation</a>
2021
*/
2122
public class GHGist extends GHObject {
22-
/* package almost final */ GHUser owner;
23-
/* package almost final */ GitHub root;
23+
24+
final GHUser owner;
25+
final GitHub root;
2426

2527
private String forks_url, commits_url, id, git_pull_url, git_push_url, html_url;
2628

@@ -33,7 +35,19 @@ public class GHGist extends GHObject {
3335

3436
private String comments_url;
3537

36-
private Map<String, GHGistFile> files = new HashMap<String, GHGistFile>();
38+
private final Map<String, GHGistFile> files;
39+
40+
@JsonCreator
41+
private GHGist(@JacksonInject GitHub root,
42+
@JsonProperty("owner") GHUser owner,
43+
@JsonProperty("files") Map<String, GHGistFile> files) {
44+
this.root = root;
45+
for (Entry<String, GHGistFile> e : files.entrySet()) {
46+
e.getValue().fileName = e.getKey();
47+
}
48+
this.files = Collections.unmodifiableMap(files);
49+
this.owner = root.getUser(owner);
50+
}
3751

3852
/**
3953
* Gets owner.
@@ -43,7 +57,7 @@ public class GHGist extends GHObject {
4357
* the io exception
4458
*/
4559
public GHUser getOwner() throws IOException {
46-
return root.intern(owner);
60+
return owner;
4761
}
4862

4963
/**
@@ -139,31 +153,7 @@ public GHGistFile getFile(String name) {
139153
* @return the files
140154
*/
141155
public Map<String, GHGistFile> getFiles() {
142-
return Collections.unmodifiableMap(files);
143-
}
144-
145-
GHGist wrapUp(GHUser owner) {
146-
this.owner = owner;
147-
this.root = owner.root;
148-
wrapUp();
149-
return this;
150-
}
151-
152-
/**
153-
* Used when caller obtains {@link GHGist} without knowing its owner. A partially constructed owner object is
154-
* interned.
155-
*/
156-
GHGist wrapUp(GitHub root) {
157-
this.owner = root.getUser(owner);
158-
this.root = root;
159-
wrapUp();
160-
return this;
161-
}
162-
163-
private void wrapUp() {
164-
for (Entry<String, GHGistFile> e : files.entrySet()) {
165-
e.getValue().fileName = e.getKey();
166-
}
156+
return files;
167157
}
168158

169159
String getApiTailUrl(String tail) {
@@ -213,7 +203,7 @@ public boolean isStarred() throws IOException {
213203
* the io exception
214204
*/
215205
public GHGist fork() throws IOException {
216-
return root.createRequest().method("POST").withUrlPath(getApiTailUrl("forks")).fetch(GHGist.class).wrapUp(root);
206+
return root.createRequest().method("POST").withUrlPath(getApiTailUrl("forks")).fetch(GHGist.class);
217207
}
218208

219209
/**
@@ -222,9 +212,7 @@ public GHGist fork() throws IOException {
222212
* @return the paged iterable
223213
*/
224214
public PagedIterable<GHGist> listForks() {
225-
return root.createRequest()
226-
.withUrlPath(getApiTailUrl("forks"))
227-
.toIterable(GHGist[].class, item -> item.wrapUp(root));
215+
return root.createRequest().withUrlPath(getApiTailUrl("forks")).toIterable(GHGist[].class, null);
228216
}
229217

230218
/**
@@ -263,10 +251,4 @@ public boolean equals(Object o) {
263251
public int hashCode() {
264252
return id.hashCode();
265253
}
266-
267-
GHGist wrap(GHUser owner) {
268-
this.owner = owner;
269-
this.root = owner.root;
270-
return this;
271-
}
272254
}

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHGistBuilder.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ public GHGistBuilder file(String fileName, String content) {
7272
*/
7373
public GHGist create() throws IOException {
7474
req.with("files", files);
75-
return req.withUrlPath("/gists").fetch(GHGist.class).wrapUp(root);
75+
return req.withUrlPath("/gists").fetch(GHGist.class);
7676
}
7777
}

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHGistUpdater.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ public GHGistUpdater description(String desc) {
9494
*/
9595
public GHGist update() throws IOException {
9696
builder.with("files", files);
97-
return builder.method("PATCH").withUrlPath(base.getApiTailUrl("")).fetch(GHGist.class).wrap(base.owner);
97+
return builder.method("PATCH").withUrlPath(base.getApiTailUrl("")).fetch(GHGist.class);
9898
}
9999
}

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHUser.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public PagedIterable<GHEventInfo> listEvents() throws IOException {
217217
public PagedIterable<GHGist> listGists() throws IOException {
218218
return root.createRequest()
219219
.withUrlPath(String.format("/users/%s/gists", login))
220-
.toIterable(GHGist[].class, item -> item.wrapUp(this));
220+
.toIterable(GHGist[].class, null);
221221
}
222222

223223
@Override

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GitHub.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ public List<GHEventInfo> getEvents() throws IOException {
743743
* the io exception
744744
*/
745745
public GHGist getGist(String id) throws IOException {
746-
return createRequest().withUrlPath("/gists/" + id).fetch(GHGist.class).wrapUp(this);
746+
return createRequest().withUrlPath("/gists/" + id).fetch(GHGist.class);
747747
}
748748

749749
/**
@@ -772,7 +772,7 @@ public GHGistBuilder createGist() {
772772
* the io exception
773773
*/
774774
public <T extends GHEventPayload> T parseEventPayload(Reader r, Class<T> type) throws IOException {
775-
T t = GitHubClient.getMappingObjectReader().forType(type).readValue(r);
775+
T t = GitHubClient.getMappingObjectReader(this).forType(type).readValue(r);
776776
t.wrapUp(this);
777777
return t;
778778
}
@@ -1184,7 +1184,7 @@ GitHubClient getClient() {
11841184

11851185
@Nonnull
11861186
Requester createRequest() {
1187-
return new Requester(client);
1187+
return new Requester(client).injectMappingValue(this);
11881188
}
11891189

11901190
GHUser intern(GHUser user) throws IOException {

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GitHubClient.java
+18-5Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,16 @@ static ObjectWriter getMappingObjectWriter() {
706706
/**
707707
* Helper for {@link #getMappingObjectReader(GitHubResponse.ResponseInfo)}
708708
*
709+
* @param root
710+
* the root GitHub object for this reader
711+
*
709712
* @return an {@link ObjectReader} instance that can be further configured.
710713
*/
711714
@Nonnull
712-
static ObjectReader getMappingObjectReader() {
713-
return getMappingObjectReader(null);
715+
static ObjectReader getMappingObjectReader(@Nonnull GitHub root) {
716+
ObjectReader reader = getMappingObjectReader((GitHubResponse.ResponseInfo) null);
717+
((InjectableValues.Std) reader.getInjectableValues()).addValue(GitHub.class, root);
718+
return reader;
714719
}
715720

716721
/**
@@ -724,13 +729,21 @@ static ObjectReader getMappingObjectReader() {
724729
*
725730
* @param responseInfo
726731
* the {@link GitHubResponse.ResponseInfo} to inject for this reader.
732+
*
727733
* @return an {@link ObjectReader} instance that can be further configured.
728734
*/
729735
@Nonnull
730736
static ObjectReader getMappingObjectReader(@CheckForNull GitHubResponse.ResponseInfo responseInfo) {
731-
InjectableValues.Std inject = new InjectableValues.Std();
732-
inject.addValue(GitHubResponse.ResponseInfo.class, responseInfo);
737+
Map<String, Object> injected = new HashMap<>();
738+
739+
// Required or many things break
740+
injected.put(GitHubResponse.ResponseInfo.class.getName(), null);
741+
injected.put(GitHub.class.getName(), null);
733742

734-
return MAPPER.reader(inject);
743+
if (responseInfo != null) {
744+
injected.put(GitHubResponse.ResponseInfo.class.getName(), responseInfo);
745+
injected.putAll(responseInfo.request().injectedMappingValues());
746+
}
747+
return MAPPER.reader(new InjectableValues.Std(injected));
735748
}
736749
}

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

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

3+
import edu.umd.cs.findbugs.annotations.NonNull;
34
import org.apache.commons.lang3.StringUtils;
45

56
import java.io.InputStream;
@@ -40,6 +41,7 @@ class GitHubRequest {
4041
private static final List<String> METHODS_WITHOUT_BODY = asList("GET", "DELETE");
4142
private final List<Entry> args;
4243
private final Map<String, String> headers;
44+
private final Map<String, Object> injectedMappingValues;
4345
private final String apiUrl;
4446
private final String urlPath;
4547
private final String method;
@@ -50,13 +52,15 @@ class GitHubRequest {
5052

5153
private GitHubRequest(@Nonnull List<Entry> args,
5254
@Nonnull Map<String, String> headers,
55+
@Nonnull Map<String, Object> injectedMappingValues,
5356
@Nonnull String apiUrl,
5457
@Nonnull String urlPath,
5558
@Nonnull String method,
5659
@CheckForNull InputStream body,
5760
boolean forceBody) throws MalformedURLException {
5861
this.args = Collections.unmodifiableList(new ArrayList<>(args));
5962
this.headers = Collections.unmodifiableMap(new LinkedHashMap<>(headers));
63+
this.injectedMappingValues = Collections.unmodifiableMap(new LinkedHashMap<>(injectedMappingValues));
6064
this.apiUrl = apiUrl;
6165
this.urlPath = urlPath;
6266
this.method = method;
@@ -136,6 +140,16 @@ public Map<String, String> headers() {
136140
return headers;
137141
}
138142

143+
/**
144+
* The headers for this request.
145+
*
146+
* @return the {@link Map} of headers
147+
*/
148+
@Nonnull
149+
public Map<String, Object> injectedMappingValues() {
150+
return injectedMappingValues;
151+
}
152+
139153
/**
140154
* The base GitHub API URL for this request represented as a {@link String}
141155
*
@@ -203,7 +217,7 @@ public boolean inBody() {
203217
* @return a {@link Builder} based on this request.
204218
*/
205219
public Builder<?> toBuilder() {
206-
return new Builder<>(args, headers, apiUrl, urlPath, method, body, forceBody);
220+
return new Builder<>(args, headers, injectedMappingValues, apiUrl, urlPath, method, body, forceBody);
207221
}
208222

209223
private String buildTailApiUrl() {
@@ -248,6 +262,12 @@ static class Builder<B extends Builder<B>> {
248262
@Nonnull
249263
private final Map<String, String> headers;
250264

265+
/**
266+
* Injected local data map
267+
*/
268+
@Nonnull
269+
private final Map<String, Object> injectedMappingValues;
270+
251271
/**
252272
* The base GitHub API for this request.
253273
*/
@@ -268,18 +288,27 @@ static class Builder<B extends Builder<B>> {
268288
* Create a new {@link GitHubRequest.Builder}
269289
*/
270290
protected Builder() {
271-
this(new ArrayList<>(), new LinkedHashMap<>(), GitHubClient.GITHUB_URL, "/", "GET", null, false);
291+
this(new ArrayList<>(),
292+
new LinkedHashMap<>(),
293+
new LinkedHashMap<>(),
294+
GitHubClient.GITHUB_URL,
295+
"/",
296+
"GET",
297+
null,
298+
false);
272299
}
273300

274301
private Builder(@Nonnull List<Entry> args,
275302
@Nonnull Map<String, String> headers,
303+
@Nonnull Map<String, Object> injectedMappingValues,
276304
@Nonnull String apiUrl,
277305
@Nonnull String urlPath,
278306
@Nonnull String method,
279307
@CheckForNull @WillClose InputStream body,
280308
boolean forceBody) {
281309
this.args = new ArrayList<>(args);
282310
this.headers = new LinkedHashMap<>(headers);
311+
this.injectedMappingValues = new LinkedHashMap<>(injectedMappingValues);
283312
this.apiUrl = apiUrl;
284313
this.urlPath = urlPath;
285314
this.method = method;
@@ -295,7 +324,7 @@ private Builder(@Nonnull List<Entry> args,
295324
* if the GitHub API URL cannot be constructed
296325
*/
297326
public GitHubRequest build() throws MalformedURLException {
298-
return new GitHubRequest(args, headers, apiUrl, urlPath, method, body, forceBody);
327+
return new GitHubRequest(args, headers, injectedMappingValues, apiUrl, urlPath, method, body, forceBody);
299328
}
300329

301330
/**
@@ -338,6 +367,31 @@ public B withHeader(String name, String value) {
338367
return (B) this;
339368
}
340369

370+
/**
371+
* Object to inject into binding.
372+
*
373+
* @param value
374+
* the value
375+
* @return the request builder
376+
*/
377+
public B injectMappingValue(@NonNull Object value) {
378+
return injectMappingValue(value.getClass().getName(), value);
379+
}
380+
381+
/**
382+
* Object to inject into binding.
383+
*
384+
* @param name
385+
* the name
386+
* @param value
387+
* the value
388+
* @return the request builder
389+
*/
390+
public B injectMappingValue(@NonNull String name, Object value) {
391+
this.injectedMappingValues.put(name, value);
392+
return (B) this;
393+
}
394+
341395
public B withPreview(String name) {
342396
return withHeader("Accept", name);
343397
}

0 commit comments

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