Compare commits
No commits in common. "stable" and "v1.1.x" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,5 @@
|
|||||||
# Maven
|
# Maven
|
||||||
target
|
target
|
||||||
pom.xml.versionsBackup
|
|
||||||
|
|
||||||
# Eclipse
|
# Eclipse
|
||||||
.project
|
.project
|
||||||
|
28
pom.xml
28
pom.xml
@ -2,10 +2,10 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.inteligr8</groupId>
|
<groupId>me.brianlong</groupId>
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.1.1</version>
|
<version>1.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<name>GitHub API & Utilities</name>
|
<name>GitHub API & Utilities</name>
|
||||||
|
|
||||||
@ -16,6 +16,16 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jgit</groupId>
|
||||||
|
<artifactId>org.eclipse.jgit</artifactId>
|
||||||
|
<version>5.9.0.202009080501-r</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jgit</groupId>
|
||||||
|
<artifactId>org.eclipse.jgit.ssh.jsch</artifactId>
|
||||||
|
<version>5.9.0.202009080501-r</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<artifactId>httpclient</artifactId>
|
<artifactId>httpclient</artifactId>
|
||||||
@ -31,11 +41,6 @@
|
|||||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
<version>2.11.0</version>
|
<version>2.11.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>1.7.30</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
@ -81,13 +86,4 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<distributionManagement>
|
|
||||||
<repository>
|
|
||||||
<id>inteligr8-releases</id>
|
|
||||||
<name>Inteligr8 Releases</name>
|
|
||||||
<url>http://repos.yateslong.us/nexus/repository/inteligr8-public</url>
|
|
||||||
<layout>default</layout>
|
|
||||||
</repository>
|
|
||||||
</distributionManagement>
|
|
||||||
</project>
|
</project>
|
||||||
|
16
src/jetty/log4j2.xml
Normal file
16
src/jetty/log4j2.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Configuration status="WARN">
|
||||||
|
<Appenders>
|
||||||
|
<Console name="STDOUT" target="SYSTEM_OUT">
|
||||||
|
<PatternLayout pattern="[%t] %-5level %logger{36} - %msg%n"/>
|
||||||
|
</Console>
|
||||||
|
</Appenders>
|
||||||
|
<Loggers>
|
||||||
|
<Logger name="me.brianlong" level="trace" additivity="false">
|
||||||
|
<AppenderRef ref="STDOUT" />
|
||||||
|
</Logger>
|
||||||
|
<Root level="trace">
|
||||||
|
<AppenderRef ref="STDOUT"/>
|
||||||
|
</Root>
|
||||||
|
</Loggers>
|
||||||
|
</Configuration>
|
@ -1,18 +0,0 @@
|
|||||||
package com.inteligr8.github.model;
|
|
||||||
|
|
||||||
public class DeleteReference {
|
|
||||||
|
|
||||||
private DeleteReference() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String constructRequestPath(String repoName, String ref) {
|
|
||||||
return "/repos/" + repoName + "/" + httpPath + "/" + ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String constructRequestPathByBranch(String repoName, String branchName) {
|
|
||||||
return constructRequestPath(repoName, "refs/heads/" + branchName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String httpPath = "git";
|
|
||||||
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.inteligr8.github;
|
package me.brianlong.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -19,13 +19,13 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.inteligr8.github.http.BaseResponse;
|
|
||||||
import com.inteligr8.github.http.PreemptiveAuthInterceptor;
|
import me.brianlong.http.BaseResponse;
|
||||||
|
import me.brianlong.http.PreemptiveAuthInterceptor;
|
||||||
|
|
||||||
public class ApiGateway {
|
public class ApiGateway {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(ApiGateway.class);
|
private final Logger logger = LoggerFactory.getLogger(ApiGateway.class);
|
||||||
private final String baseUrl = "https://api.github.com";
|
|
||||||
private ObjectMapper omapper = new ObjectMapper();
|
private ObjectMapper omapper = new ObjectMapper();
|
||||||
private CredentialsProvider credProvider;
|
private CredentialsProvider credProvider;
|
||||||
|
|
||||||
@ -33,29 +33,29 @@ public class ApiGateway {
|
|||||||
this.credProvider = credProvider;
|
this.credProvider = credProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <Response extends BaseResponse> Response get(String uriPath, Map<String, Object> paramMap, Class<Response> responseType) throws IOException {
|
public <Response extends BaseResponse> Response get(String uri, Map<String, Object> paramMap, Class<Response> responseType) throws IOException {
|
||||||
return this.execute(HttpGet.METHOD_NAME, uriPath, paramMap, null, responseType);
|
return this.execute(HttpGet.METHOD_NAME, uri, paramMap, null, responseType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <Request, Response extends BaseResponse> Response post(String uriPath, Request requestObject, Class<Response> responseType) throws IOException {
|
public <Request, Response extends BaseResponse> Response post(String uri, Request requestObject, Class<Response> responseType) throws IOException {
|
||||||
return this.execute(HttpPost.METHOD_NAME, uriPath, null, requestObject, responseType);
|
return this.execute(HttpPost.METHOD_NAME, uri, null, requestObject, responseType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <Request, Response extends BaseResponse> Response put(String uriPath, Request requestObject, Class<Response> responseType) throws IOException {
|
public <Request, Response extends BaseResponse> Response put(String uri, Request requestObject, Class<Response> responseType) throws IOException {
|
||||||
return this.execute(HttpPost.METHOD_NAME, uriPath, null, requestObject, responseType);
|
return this.execute(HttpPost.METHOD_NAME, uri, null, requestObject, responseType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <Response extends BaseResponse> Response delete(String uriPath, Map<String, Object> paramMap, Class<Response> responseType) throws IOException {
|
public <Response extends BaseResponse> Response delete(String uri, Map<String, Object> paramMap, Class<Response> responseType) throws IOException {
|
||||||
return this.execute(HttpDelete.METHOD_NAME, uriPath, paramMap, null, responseType);
|
return this.execute(HttpDelete.METHOD_NAME, uri, paramMap, null, responseType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <Request, Response extends BaseResponse> Response execute(String method, String uriPath, Map<String, Object> paramMap, Request requestObject, Class<Response> responseType) throws IOException {
|
private <Request, Response extends BaseResponse> Response execute(String method, String uri, Map<String, Object> paramMap, Request requestObject, Class<Response> responseType) throws IOException {
|
||||||
if (this.logger.isTraceEnabled())
|
if (this.logger.isTraceEnabled())
|
||||||
this.logger.trace("execute('" + method + "', '" + uriPath + "')");
|
this.logger.trace("execute('" + method + "', '" + uri + "')");
|
||||||
|
|
||||||
RequestBuilder builder = RequestBuilder
|
RequestBuilder builder = RequestBuilder
|
||||||
.create(method)
|
.create(method)
|
||||||
.setUri(this.baseUrl + uriPath);
|
.setUri(uri);
|
||||||
|
|
||||||
if (paramMap != null) {
|
if (paramMap != null) {
|
||||||
for (Entry<String, Object> param : paramMap.entrySet())
|
for (Entry<String, Object> param : paramMap.entrySet())
|
||||||
@ -66,14 +66,14 @@ public class ApiGateway {
|
|||||||
if (requestObject != null) {
|
if (requestObject != null) {
|
||||||
String requestJson = this.omapper.writeValueAsString(requestObject);
|
String requestJson = this.omapper.writeValueAsString(requestObject);
|
||||||
if (this.logger.isTraceEnabled())
|
if (this.logger.isTraceEnabled())
|
||||||
this.logger.trace("execute('" + method + "', '" + uriPath + "'): " + requestJson);
|
this.logger.trace("execute('" + method + "', '" + uri + "'): " + requestJson);
|
||||||
|
|
||||||
builder.setEntity(new StringEntity(requestJson, ContentType.APPLICATION_JSON));
|
builder.setEntity(new StringEntity(requestJson, ContentType.APPLICATION_JSON));
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpUriRequest request = builder.build();
|
HttpUriRequest request = builder.build();
|
||||||
if (this.logger.isDebugEnabled())
|
if (this.logger.isDebugEnabled())
|
||||||
this.logger.debug("Prepared request for " + method + " to: " + uriPath);
|
this.logger.debug("Prepared request for " + method + " to: " + uri);
|
||||||
|
|
||||||
HttpResponse response = HttpClientBuilder
|
HttpResponse response = HttpClientBuilder
|
||||||
.create()
|
.create()
|
||||||
@ -84,21 +84,15 @@ public class ApiGateway {
|
|||||||
if (this.logger.isDebugEnabled())
|
if (this.logger.isDebugEnabled())
|
||||||
this.logger.debug("Received response from " + method + ": " + response.getStatusLine().getStatusCode());
|
this.logger.debug("Received response from " + method + ": " + response.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
Response responseObject = null;
|
InputStream istream = response.getEntity().getContent();
|
||||||
if (response.getEntity() != null) {
|
try {
|
||||||
InputStream istream = response.getEntity().getContent();
|
Response responseObject = this.omapper.readerFor(responseType).readValue(istream);
|
||||||
try {
|
responseObject.setHttpStatusCode(response.getStatusLine().getStatusCode());
|
||||||
responseObject = this.omapper.readerFor(responseType).readValue(istream);
|
responseObject.setHttpStatusReason(response.getStatusLine().getReasonPhrase());
|
||||||
} finally {
|
return responseObject;
|
||||||
istream.close();
|
} finally {
|
||||||
}
|
istream.close();
|
||||||
} else {
|
|
||||||
responseObject = this.omapper.readerFor(responseType).readValue("{}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
responseObject.setHttpStatusCode(response.getStatusLine().getStatusCode());
|
|
||||||
responseObject.setHttpStatusReason(response.getStatusLine().getReasonPhrase());
|
|
||||||
return responseObject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,18 +1,15 @@
|
|||||||
package com.inteligr8.github.model;
|
package me.brianlong.github.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.inteligr8.github.http.BaseResponse;
|
|
||||||
|
import me.brianlong.http.BaseResponse;
|
||||||
|
|
||||||
public class CreatePullRequest {
|
public class CreatePullRequest {
|
||||||
|
|
||||||
private CreatePullRequest() {
|
private CreatePullRequest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String constructRequestPath(String repoName) {
|
|
||||||
return "/repos/" + repoName + "/" + httpPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String httpPath = "pulls";
|
public static String httpPath = "pulls";
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
@ -1,18 +1,15 @@
|
|||||||
package com.inteligr8.github.model;
|
package me.brianlong.github.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.inteligr8.github.http.BaseResponse;
|
|
||||||
|
import me.brianlong.http.BaseResponse;
|
||||||
|
|
||||||
public class CreateReference {
|
public class CreateReference {
|
||||||
|
|
||||||
private CreateReference() {
|
private CreateReference() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String constructRequestPath(String repoName) {
|
|
||||||
return "/repos/" + repoName + "/" + httpPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String httpPath = "git/refs";
|
public static String httpPath = "git/refs";
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
@ -1,4 +1,4 @@
|
|||||||
package com.inteligr8.github.http;
|
package me.brianlong.http;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.inteligr8.github.http;
|
package me.brianlong.http;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user