Skip to content

Commit

Permalink
Introduce request and response interfaces for GitHubConnector
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Nov 8, 2021
1 parent 58242c9 commit 8756674
Show file tree
Hide file tree
Showing 27 changed files with 468 additions and 370 deletions.
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@
</annotationProcessorPaths>
</configuration>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
Expand Down Expand Up @@ -579,7 +578,7 @@
</goals>
<configuration>
<excludesFile>src/test/resources/slow-or-flaky-tests.txt</excludesFile>
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.useOkHttp</argLine>
<argLine>@{jacoco.surefire.argLine} ${surefire.argLine} -Dtest.github.connector=okhttp</argLine>
</configuration>
</execution>
<execution>
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/org/kohsuke/github/AbuseLimitHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.kohsuke.github;

import org.kohsuke.github.connector.GitHubConnectorResponse;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.HttpURLConnection;
Expand All @@ -22,7 +24,7 @@ public abstract class AbuseLimitHandler {
* an exception. If this method returns normally, another request will be attempted. For that to make sense, the
* implementation needs to wait for some time.
*
* @param responseInfo
* @param connectorResponse
* Response information for this request.
* @throws IOException
* on failure
Expand All @@ -32,12 +34,12 @@ public abstract class AbuseLimitHandler {
* with abuse rate limits</a>
*
*/
void onError(GitHubResponse.ResponseInfo responseInfo) throws IOException {
void onError(GitHubConnectorResponse connectorResponse) throws IOException {
GHIOException e = new HttpException("Abuse limit violation",
responseInfo.statusCode(),
responseInfo.header("Status"),
responseInfo.url().toString()).withResponseHeaderFields(responseInfo.allHeaders());
onError(e, new GitHubResponseInfoHttpURLConnectionAdapter(responseInfo));
connectorResponse.statusCode(),
connectorResponse.header("Status"),
connectorResponse.url().toString()).withResponseHeaderFields(connectorResponse.allHeaders());
onError(e, new GitHubResponseInfoHttpURLConnectionAdapter(connectorResponse));
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/kohsuke/github/GHObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.kohsuke.github.connector.GitHubConnectorResponse;

import java.io.IOException;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -39,13 +40,13 @@ public abstract class GHObject extends GitHubInteractiveObject {
/**
* Called by Jackson
*
* @param responseInfo
* the {@link GitHubResponse.ResponseInfo} to get headers from.
* @param connectorResponse
* the {@link GitHubConnectorResponse} to get headers from.
*/
@JacksonInject
protected void setResponseHeaderFields(@CheckForNull GitHubResponse.ResponseInfo responseInfo) {
if (responseInfo != null) {
responseHeaderFields = responseInfo.allHeaders();
protected void setResponseHeaderFields(@CheckForNull GitHubConnectorResponse connectorResponse) {
if (connectorResponse != null) {
responseHeaderFields = connectorResponse.allHeaders();
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/kohsuke/github/GHRateLimit.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.StringUtils;
import org.kohsuke.github.connector.GitHubConnectorResponse;

import java.time.Duration;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -436,20 +437,20 @@ public Record(@JsonProperty(value = "limit", required = true) int limit,
* the remaining
* @param resetEpochSeconds
* the reset epoch seconds
* @param responseInfo
* @param connectorResponse
* the response info
*/
@JsonCreator
Record(@JsonProperty(value = "limit", required = true) int limit,
@JsonProperty(value = "remaining", required = true) int remaining,
@JsonProperty(value = "reset", required = true) long resetEpochSeconds,
@JacksonInject @CheckForNull GitHubResponse.ResponseInfo responseInfo) {
@JacksonInject @CheckForNull GitHubConnectorResponse connectorResponse) {
this.limit = limit;
this.remaining = remaining;
this.resetEpochSeconds = resetEpochSeconds;
String updatedAt = null;
if (responseInfo != null) {
updatedAt = responseInfo.header("Date");
if (connectorResponse != null) {
updatedAt = connectorResponse.header("Date");
}
this.resetDate = calculateResetDate(updatedAt);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.kohsuke.github.authorization.AuthorizationProvider;
import org.kohsuke.github.authorization.ImmutableAuthorizationProvider;
import org.kohsuke.github.authorization.UserAuthorizationProvider;
import org.kohsuke.github.connector.GitHubConnector;
import org.kohsuke.github.internal.GitHubConnectorHttpConnectorAdapter;
import org.kohsuke.github.internal.Previews;

import java.io.*;
Expand Down Expand Up @@ -470,7 +472,10 @@ public boolean isOffline() {
* Gets connector.
*
* @return the connector
* @deprecated HttpConnector has been replaced by GitHubConnector which is generally not useful outside of this
* library. If you are using
*/
@Deprecated
public HttpConnector getConnector() {
return client.getConnector();
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/kohsuke/github/GitHubBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import org.apache.commons.io.IOUtils;
import org.kohsuke.github.authorization.AuthorizationProvider;
import org.kohsuke.github.authorization.ImmutableAuthorizationProvider;
import org.kohsuke.github.connector.GitHubConnector;
import org.kohsuke.github.extras.ImpatientHttpConnector;
import org.kohsuke.github.internal.GitHubConnectorHttpConnectorAdapter;

import java.io.File;
import java.io.FileInputStream;
Expand Down
Loading

0 comments on commit 8756674

Please sign in to comment.