Skip to content

Commit 9db400d

Browse files
committed
Introduce request and response interfaces for GitHubConnector
1 parent 3a903a2 commit 9db400d

27 files changed

+470
-371
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
<exclude>org.kohsuke.github.GHCompare.User</exclude>
166166

167167
<!-- TODO: Some coverage, but more needed -->
168+
<exclude>org.kohsuke.github.GitHubResponseInfoHttpURLConnectionAdapter</exclude>
168169
<exclude>org.kohsuke.github.GHPullRequestReviewBuilder.DraftReviewComment</exclude>
169170
<exclude>org.kohsuke.github.GHIssue.PullRequest</exclude>
170171
<exclude>org.kohsuke.github.GHCommitSearchBuilder</exclude>
@@ -266,7 +267,6 @@
266267
</annotationProcessorPaths>
267268
</configuration>
268269
</plugin>
269-
270270
<plugin>
271271
<artifactId>maven-surefire-plugin</artifactId>
272272
<executions>
@@ -579,7 +579,7 @@
579579
</goals>
580580
<configuration>
581581
<excludesFile>src/test/resources/slow-or-flaky-tests.txt</excludesFile>
582-
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.useOkHttp</argLine>
582+
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.connector=okhttp</argLine>
583583
</configuration>
584584
</execution>
585585
<execution>

src/main/java/org/kohsuke/github/AbuseLimitHandler.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.kohsuke.github;
22

3+
import org.kohsuke.github.connector.GitHubConnectorResponse;
4+
35
import java.io.IOException;
46
import java.io.InterruptedIOException;
57
import java.net.HttpURLConnection;
@@ -22,7 +24,7 @@ public abstract class AbuseLimitHandler {
2224
* an exception. If this method returns normally, another request will be attempted. For that to make sense, the
2325
* implementation needs to wait for some time.
2426
*
25-
* @param responseInfo
27+
* @param connectorResponse
2628
* Response information for this request.
2729
* @throws IOException
2830
* on failure
@@ -32,12 +34,12 @@ public abstract class AbuseLimitHandler {
3234
* with abuse rate limits</a>
3335
*
3436
*/
35-
void onError(GitHubResponse.ResponseInfo responseInfo) throws IOException {
37+
void onError(GitHubConnectorResponse connectorResponse) throws IOException {
3638
GHIOException e = new HttpException("Abuse limit violation",
37-
responseInfo.statusCode(),
38-
responseInfo.header("Status"),
39-
responseInfo.url().toString()).withResponseHeaderFields(responseInfo.allHeaders());
40-
onError(e, new GitHubResponseInfoHttpURLConnectionAdapter(responseInfo));
39+
connectorResponse.statusCode(),
40+
connectorResponse.header("Status"),
41+
connectorResponse.url().toString()).withResponseHeaderFields(connectorResponse.allHeaders());
42+
onError(e, new GitHubResponseInfoHttpURLConnectionAdapter(connectorResponse));
4143
}
4244

4345
/**

src/main/java/org/kohsuke/github/GHObject.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
66
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
77
import org.apache.commons.lang3.builder.ToStringStyle;
8+
import org.kohsuke.github.connector.GitHubConnectorResponse;
89

910
import java.io.IOException;
1011
import java.lang.reflect.Field;
@@ -39,13 +40,13 @@ public abstract class GHObject extends GitHubInteractiveObject {
3940
/**
4041
* Called by Jackson
4142
*
42-
* @param responseInfo
43-
* the {@link GitHubResponse.ResponseInfo} to get headers from.
43+
* @param connectorResponse
44+
* the {@link GitHubConnectorResponse} to get headers from.
4445
*/
4546
@JacksonInject
46-
protected void setResponseHeaderFields(@CheckForNull GitHubResponse.ResponseInfo responseInfo) {
47-
if (responseInfo != null) {
48-
responseHeaderFields = responseInfo.allHeaders();
47+
protected void setResponseHeaderFields(@CheckForNull GitHubConnectorResponse connectorResponse) {
48+
if (connectorResponse != null) {
49+
responseHeaderFields = connectorResponse.allHeaders();
4950
}
5051
}
5152

src/main/java/org/kohsuke/github/GHRateLimit.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.annotation.JsonProperty;
66
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
77
import org.apache.commons.lang3.StringUtils;
8+
import org.kohsuke.github.connector.GitHubConnectorResponse;
89

910
import java.time.Duration;
1011
import java.time.ZonedDateTime;
@@ -436,20 +437,20 @@ public Record(@JsonProperty(value = "limit", required = true) int limit,
436437
* the remaining
437438
* @param resetEpochSeconds
438439
* the reset epoch seconds
439-
* @param responseInfo
440+
* @param connectorResponse
440441
* the response info
441442
*/
442443
@JsonCreator
443444
Record(@JsonProperty(value = "limit", required = true) int limit,
444445
@JsonProperty(value = "remaining", required = true) int remaining,
445446
@JsonProperty(value = "reset", required = true) long resetEpochSeconds,
446-
@JacksonInject @CheckForNull GitHubResponse.ResponseInfo responseInfo) {
447+
@JacksonInject @CheckForNull GitHubConnectorResponse connectorResponse) {
447448
this.limit = limit;
448449
this.remaining = remaining;
449450
this.resetEpochSeconds = resetEpochSeconds;
450451
String updatedAt = null;
451-
if (responseInfo != null) {
452-
updatedAt = responseInfo.header("Date");
452+
if (connectorResponse != null) {
453+
updatedAt = connectorResponse.header("Date");
453454
}
454455
this.resetDate = calculateResetDate(updatedAt);
455456
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.kohsuke.github.authorization.AuthorizationProvider;
3131
import org.kohsuke.github.authorization.ImmutableAuthorizationProvider;
3232
import org.kohsuke.github.authorization.UserAuthorizationProvider;
33+
import org.kohsuke.github.connector.GitHubConnector;
34+
import org.kohsuke.github.internal.GitHubConnectorHttpConnectorAdapter;
3335
import org.kohsuke.github.internal.Previews;
3436

3537
import java.io.*;
@@ -470,7 +472,10 @@ public boolean isOffline() {
470472
* Gets connector.
471473
*
472474
* @return the connector
475+
* @deprecated HttpConnector has been replaced by GitHubConnector which is generally not useful outside of this
476+
* library. If you are using
473477
*/
478+
@Deprecated
474479
public HttpConnector getConnector() {
475480
return client.getConnector();
476481
}

src/main/java/org/kohsuke/github/GitHubBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import org.apache.commons.io.IOUtils;
44
import org.kohsuke.github.authorization.AuthorizationProvider;
55
import org.kohsuke.github.authorization.ImmutableAuthorizationProvider;
6+
import org.kohsuke.github.connector.GitHubConnector;
67
import org.kohsuke.github.extras.ImpatientHttpConnector;
8+
import org.kohsuke.github.internal.GitHubConnectorHttpConnectorAdapter;
79

810
import java.io.File;
911
import java.io.FileInputStream;

0 commit comments

Comments
 (0)