mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish StandardGitHub
This commit is contained in:
parent
aca087e762
commit
b3644c1a99
@ -16,17 +16,12 @@
|
|||||||
|
|
||||||
package org.springframework.boot.build.bom.bomr.github;
|
package org.springframework.boot.build.bom.bomr.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import org.springframework.http.HttpRequest;
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.client.ClientHttpRequestExecution;
|
|
||||||
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
|
||||||
import org.springframework.http.client.ClientHttpResponse;
|
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.util.DefaultUriBuilderFactory;
|
import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||||
@ -51,19 +46,13 @@ final class StandardGitHub implements GitHub {
|
|||||||
@Override
|
@Override
|
||||||
public GitHubRepository getRepository(String organization, String name) {
|
public GitHubRepository getRepository(String organization, String name) {
|
||||||
RestTemplate restTemplate = new RestTemplate(
|
RestTemplate restTemplate = new RestTemplate(
|
||||||
Arrays.asList(new MappingJackson2HttpMessageConverter(new ObjectMapper())));
|
Collections.singletonList(new MappingJackson2HttpMessageConverter(new ObjectMapper())));
|
||||||
restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() {
|
restTemplate.getInterceptors().add((request, body, execution) -> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
|
|
||||||
throws IOException {
|
|
||||||
request.getHeaders().add("User-Agent", StandardGitHub.this.username);
|
request.getHeaders().add("User-Agent", StandardGitHub.this.username);
|
||||||
request.getHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString(
|
request.getHeaders().add("Authorization", "Basic " + Base64.getEncoder()
|
||||||
(StandardGitHub.this.username + ":" + StandardGitHub.this.password).getBytes()));
|
.encodeToString((StandardGitHub.this.username + ":" + StandardGitHub.this.password).getBytes()));
|
||||||
request.getHeaders().add("Accept", MediaType.APPLICATION_JSON_VALUE);
|
request.getHeaders().add("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
return execution.execute(request, body);
|
return execution.execute(request, body);
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
UriTemplateHandler uriTemplateHandler = new DefaultUriBuilderFactory(
|
UriTemplateHandler uriTemplateHandler = new DefaultUriBuilderFactory(
|
||||||
"https://api.github.com/repos/" + organization + "/" + name + "/");
|
"https://api.github.com/repos/" + organization + "/" + name + "/");
|
||||||
|
Loading…
Reference in New Issue
Block a user