mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.springframework.http.HttpRequest;
|
||||
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.web.client.RestTemplate;
|
||||
import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||
@ -51,19 +46,13 @@ final class StandardGitHub implements GitHub {
|
||||
@Override
|
||||
public GitHubRepository getRepository(String organization, String name) {
|
||||
RestTemplate restTemplate = new RestTemplate(
|
||||
Arrays.asList(new MappingJackson2HttpMessageConverter(new ObjectMapper())));
|
||||
restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() {
|
||||
|
||||
@Override
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
|
||||
throws IOException {
|
||||
request.getHeaders().add("User-Agent", StandardGitHub.this.username);
|
||||
request.getHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString(
|
||||
(StandardGitHub.this.username + ":" + StandardGitHub.this.password).getBytes()));
|
||||
request.getHeaders().add("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
return execution.execute(request, body);
|
||||
}
|
||||
|
||||
Collections.singletonList(new MappingJackson2HttpMessageConverter(new ObjectMapper())));
|
||||
restTemplate.getInterceptors().add((request, body, execution) -> {
|
||||
request.getHeaders().add("User-Agent", StandardGitHub.this.username);
|
||||
request.getHeaders().add("Authorization", "Basic " + Base64.getEncoder()
|
||||
.encodeToString((StandardGitHub.this.username + ":" + StandardGitHub.this.password).getBytes()));
|
||||
request.getHeaders().add("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
return execution.execute(request, body);
|
||||
});
|
||||
UriTemplateHandler uriTemplateHandler = new DefaultUriBuilderFactory(
|
||||
"https://api.github.com/repos/" + organization + "/" + name + "/");
|
||||
|
Loading…
Reference in New Issue
Block a user