diff --git a/build.gradle b/build.gradle index 17e6bdf3..5336638a 100644 --- a/build.gradle +++ b/build.gradle @@ -37,6 +37,7 @@ configure(allprojects) { repositories { maven { url "http://repo.spring.io/libs-snapshot" } maven { url "http://repo.spring.io/ebr-maven-external" } + mavenLocal() } dependencies { diff --git a/spring-social-github/src/main/java/org/springframework/social/github/api/UserOperations.java b/spring-social-github/src/main/java/org/springframework/social/github/api/UserOperations.java index 5bf441a2..4bfbd26e 100644 --- a/spring-social-github/src/main/java/org/springframework/social/github/api/UserOperations.java +++ b/spring-social-github/src/main/java/org/springframework/social/github/api/UserOperations.java @@ -60,4 +60,12 @@ public interface UserOperations { * @return list of users the given user is following */ List getFollowing(String user); + + /** + * Public operation to return the repos being watched by given user. + * + * @param user GitHub user + * @return list of repos being watched by given user + */ + List getWatching(String user); } diff --git a/spring-social-github/src/main/java/org/springframework/social/github/api/impl/AbstractGitHubOperations.java b/spring-social-github/src/main/java/org/springframework/social/github/api/impl/AbstractGitHubOperations.java index afcbf0b5..b01d669a 100644 --- a/spring-social-github/src/main/java/org/springframework/social/github/api/impl/AbstractGitHubOperations.java +++ b/spring-social-github/src/main/java/org/springframework/social/github/api/impl/AbstractGitHubOperations.java @@ -16,6 +16,7 @@ package org.springframework.social.github.api.impl; import org.springframework.social.MissingAuthorizationException; +import org.springframework.social.github.connect.GitHubHostUtils; /** *

@@ -26,11 +27,17 @@ */ class AbstractGitHubOperations { private final boolean isAuthorized; + private String gitHubHost; public AbstractGitHubOperations(boolean isAuthorized) { this.isAuthorized = isAuthorized; } + public AbstractGitHubOperations(boolean isAuthorized, String gitHubHost) { + this.isAuthorized = isAuthorized; + this.gitHubHost = gitHubHost; + } + protected void requireAuthorization() { if (!isAuthorized) { throw new MissingAuthorizationException("github"); @@ -40,9 +47,7 @@ protected void requireAuthorization() { // Using String here instead of URI so I can include braces in the path. See, e.g., RepoTemplate. [WLW] protected String buildUri(String path) { // return URIBuilder.fromUri(API_URL_BASE + path).build(); - return API_URL_BASE + path; + return GitHubHostUtils.getGitHubApi(gitHubHost) + path; } - // GitHub API v3 - private static final String API_URL_BASE = "https://api.github.com/"; } diff --git a/spring-social-github/src/main/java/org/springframework/social/github/api/impl/GistTemplate.java b/spring-social-github/src/main/java/org/springframework/social/github/api/impl/GistTemplate.java index eb303edf..4728ffec 100644 --- a/spring-social-github/src/main/java/org/springframework/social/github/api/impl/GistTemplate.java +++ b/spring-social-github/src/main/java/org/springframework/social/github/api/impl/GistTemplate.java @@ -43,6 +43,16 @@ public GistTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser) { super(isAuthorizedForUser); this.restTemplate = restTemplate; } + + /** + * @param restTemplate A RestTemplate + * @param isAuthorizedForUser Boolean indicating whether the RestTemplate is authorized for a user + * @param gitHubHost github host + */ + public GistTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser, String gitHubHost) { + super(isAuthorizedForUser,gitHubHost); + this.restTemplate = restTemplate; + } public List getUserGists(String user) { return asList(restTemplate.getForObject(buildUri("users/{user}/gists"), GitHubGist[].class, user)); diff --git a/spring-social-github/src/main/java/org/springframework/social/github/api/impl/GitHubTemplate.java b/spring-social-github/src/main/java/org/springframework/social/github/api/impl/GitHubTemplate.java index 6bc1400c..262353f7 100644 --- a/spring-social-github/src/main/java/org/springframework/social/github/api/impl/GitHubTemplate.java +++ b/spring-social-github/src/main/java/org/springframework/social/github/api/impl/GitHubTemplate.java @@ -30,59 +30,70 @@ *

* The central class for interacting with GitHub. *

+ * * @author Craig Walls * @author Willie Wheeler (willie.wheeler@gmail.com) * @author Andy Wilkinson */ public class GitHubTemplate extends AbstractOAuth2ApiBinding implements GitHub { - private GistOperations gistOperations; - private RepoOperations repoOperations; - private UserOperations userOperations; - - /** - * No-arg constructor to support cases in which you want to call the GitHub - * API without requiring authorization. This is useful for public operations, - * such as getting the list of watchers for a public repository. - */ - public GitHubTemplate() { - super(); - initSubApis(); - } - - /** - * Constructs a GitHubTemplate with the minimal amount of information - * required to sign requests with an OAuth Authorization - * header. - * - * @param accessToken - * An access token granted to the application after OAuth - * authentication. - */ - public GitHubTemplate(String accessToken) { - super(accessToken); - initSubApis(); - } - - @Override - protected OAuth2Version getOAuth2Version() { - return OAuth2Version.BEARER; - } - - public GistOperations gistOperations() { - return gistOperations; - } - - public RepoOperations repoOperations() { - return repoOperations; - } - - public UserOperations userOperations() { - return userOperations; - } - - public RestOperations restOperations() { - return getRestTemplate(); - } + private GistOperations gistOperations; + + private RepoOperations repoOperations; + + private UserOperations userOperations; + + /** + * No-arg constructor to support cases in which you want to call the GitHub API without requiring authorization. + * This is useful for public operations, such as getting the list of watchers for a public repository. + */ + public GitHubTemplate() { + super(); + initSubApis(null); + } + + /** + * Constructs a GitHubTemplate with the minimal amount of information required to sign requests with an OAuth + * Authorization header. + * + * @param accessToken An access token granted to the application after OAuth authentication. + */ + public GitHubTemplate(String accessToken) { + super(accessToken); + initSubApis(null); + } + + /** + * Constructs a GitHubTemplate with the minimal amount of information required to sign requests with an OAuth + * Authorization header. + * + * @param accessToken An access token granted to the application after OAuth authentication. + * @param gitHubHost github host + */ + public GitHubTemplate(String accessToken, String gitHubHost) { + super(accessToken); + initSubApis(gitHubHost); + } + + @Override + protected OAuth2Version getOAuth2Version() { + return OAuth2Version.BEARER; + } + + public GistOperations gistOperations() { + return gistOperations; + } + + public RepoOperations repoOperations() { + return repoOperations; + } + + public UserOperations userOperations() { + return userOperations; + } + + public RestOperations restOperations() { + return getRestTemplate(); + } @Override protected MappingJackson2HttpMessageConverter getJsonMessageConverter() { @@ -94,11 +105,11 @@ protected MappingJackson2HttpMessageConverter getJsonMessageConverter() { } // internal helpers - - private void initSubApis() { - this.gistOperations = new GistTemplate(getRestTemplate(), isAuthorized()); - this.repoOperations = new RepoTemplate(getRestTemplate(), isAuthorized()); - this.userOperations = new UserTemplate(getRestTemplate(), isAuthorized()); - } + + private void initSubApis(String githubHost) { + this.gistOperations = new GistTemplate(getRestTemplate(), isAuthorized(), githubHost); + this.repoOperations = new RepoTemplate(getRestTemplate(), isAuthorized(), githubHost); + this.userOperations = new UserTemplate(getRestTemplate(), isAuthorized(), githubHost); + } } diff --git a/spring-social-github/src/main/java/org/springframework/social/github/api/impl/RepoTemplate.java b/spring-social-github/src/main/java/org/springframework/social/github/api/impl/RepoTemplate.java index b3f7a0d5..4e6e73e0 100644 --- a/spring-social-github/src/main/java/org/springframework/social/github/api/impl/RepoTemplate.java +++ b/spring-social-github/src/main/java/org/springframework/social/github/api/impl/RepoTemplate.java @@ -49,6 +49,16 @@ public RepoTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser) { this.restTemplate = restTemplate; } + /** + * @param restTemplate A RestTemplate + * @param isAuthorizedForUser Boolean indicating whether the RestTemplate is authorized for a user + * @param gitHubHost github host + */ + public RepoTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser, String gitHubHost) { + super(isAuthorizedForUser,gitHubHost); + this.restTemplate = restTemplate; + } + public GitHubRepo getRepo(String user, String repo) { return restTemplate.getForObject(buildRepoUri(""), GitHubRepo.class, user, repo); } diff --git a/spring-social-github/src/main/java/org/springframework/social/github/api/impl/UserTemplate.java b/spring-social-github/src/main/java/org/springframework/social/github/api/impl/UserTemplate.java index c76c8cd5..0bcbd57c 100644 --- a/spring-social-github/src/main/java/org/springframework/social/github/api/impl/UserTemplate.java +++ b/spring-social-github/src/main/java/org/springframework/social/github/api/impl/UserTemplate.java @@ -25,6 +25,7 @@ import java.util.Locale; import java.util.Map; +import org.springframework.social.github.api.GitHubRepo; import org.springframework.social.github.api.GitHubUser; import org.springframework.social.github.api.GitHubUserProfile; import org.springframework.social.github.api.UserOperations; @@ -37,54 +38,67 @@ * * @author Willie Wheeler (willie.wheeler@gmail.com) * @author Andy Wilkinson + * @author Vinayak Hulawale */ public class UserTemplate extends AbstractGitHubOperations implements UserOperations { - private final RestTemplate restTemplate; - - /** - * @param restTemplate A RestTemplate - * @param isAuthorizedForUser Boolean indicating whether the RestTemplate is authorized for a user - */ - public UserTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser) { - super(isAuthorizedForUser); - this.restTemplate = restTemplate; - } - - public List getFollowers(String user) { - return asList(restTemplate.getForObject(buildUserUri("/followers"), GitHubUser[].class, user)); - } - - public List getFollowing(String user) { - return asList(restTemplate.getForObject(buildUserUri("/following"), GitHubUser[].class, user)); - } - - public String getProfileId() { - return getUserProfile().getLogin(); - } - - public GitHubUserProfile getUserProfile() { - return restTemplate.getForObject(buildUri("user"), GitHubUserProfile.class); - } - - public String getProfileUrl() { - return "https://github.com/" + getUserProfile().getLogin(); - } - - - - private String buildUserUri(String path) { - return buildUri("users/{user}" + path); - } - - private Date toDate(String dateString, DateFormat dateFormat) { - try { - return dateFormat.parse(dateString); - } catch (ParseException e) { - return null; - } - } - - private DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss Z", Locale.ENGLISH); - + private final RestTemplate restTemplate; + + /** + * @param restTemplate A RestTemplate + * @param isAuthorizedForUser Boolean indicating whether the RestTemplate is authorized for a user + */ + public UserTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser) { + super(isAuthorizedForUser); + this.restTemplate = restTemplate; + } + + /** + * @param restTemplate A RestTemplate + * @param isAuthorizedForUser Boolean indicating whether the RestTemplate is authorized for a user + * @param gitHubHost github host + */ + public UserTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser, String gitHubHost) { + super(isAuthorizedForUser, gitHubHost); + this.restTemplate = restTemplate; + } + + public List getFollowers(String user) { + return asList(restTemplate.getForObject(buildUserUri("/followers"), GitHubUser[].class, user)); + } + + public List getFollowing(String user) { + return asList(restTemplate.getForObject(buildUserUri("/following"), GitHubUser[].class, user)); + } + + public List getWatching(String user) { + return asList(restTemplate.getForObject(buildUserUri("/subscriptions"), GitHubRepo[].class, user)); + } + + public String getProfileId() { + return getUserProfile().getLogin(); + } + + public GitHubUserProfile getUserProfile() { + return restTemplate.getForObject(buildUri("user"), GitHubUserProfile.class); + } + + public String getProfileUrl() { + return buildUri("") + getUserProfile().getLogin(); + } + + private String buildUserUri(String path) { + return buildUri("users/{user}" + path); + } + + private Date toDate(String dateString, DateFormat dateFormat) { + try { + return dateFormat.parse(dateString); + } catch (ParseException e) { + return null; + } + } + + private DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss Z", Locale.ENGLISH); + } diff --git a/spring-social-github/src/main/java/org/springframework/social/github/config/xml/GitHubConfigBeanDefinitionParser.java b/spring-social-github/src/main/java/org/springframework/social/github/config/xml/GitHubConfigBeanDefinitionParser.java index 38f134e5..243783f6 100644 --- a/spring-social-github/src/main/java/org/springframework/social/github/config/xml/GitHubConfigBeanDefinitionParser.java +++ b/spring-social-github/src/main/java/org/springframework/social/github/config/xml/GitHubConfigBeanDefinitionParser.java @@ -31,6 +31,7 @@ import org.springframework.social.github.connect.GitHubConnectionFactory; import org.springframework.social.github.security.GitHubAuthenticationService; import org.springframework.social.security.provider.SocialAuthenticationService; +import org.springframework.util.StringUtils; /** * Implementation of {@link AbstractConnectionFactoryBeanDefinitionParser} that creates a {@link GitHubConnectionFactory}. @@ -50,6 +51,9 @@ protected Class> getAuthenticationServi @Override protected BeanDefinition getConnectionFactoryBeanDefinition(String appId, String appSecret, Map allAttributes) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(GitHubConnectionFactory.class).addConstructorArgValue(appId).addConstructorArgValue(appSecret); + if(StringUtils.hasText((String)allAttributes.get("app-host"))) { + builder.addConstructorArgValue((String)allAttributes.get("app-host")); + } return builder.getBeanDefinition(); } diff --git a/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubAdapter.java b/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubAdapter.java index f9ea4fb6..da25d3c9 100644 --- a/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubAdapter.java +++ b/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubAdapter.java @@ -21,6 +21,7 @@ import org.springframework.social.connect.UserProfileBuilder; import org.springframework.social.github.api.GitHub; import org.springframework.social.github.api.GitHubUserProfile; +import org.springframework.util.StringUtils; import org.springframework.web.client.HttpClientErrorException; /** @@ -29,6 +30,16 @@ * @author Andy Wilkinson */ public class GitHubAdapter implements ApiAdapter { + + private String gitHubHost ; + + public GitHubAdapter() { + setGitHubHost(null); + } + + public GitHubAdapter(String gitHubHost) { + setGitHubHost(gitHubHost); + } public boolean test(GitHub github) { try { @@ -44,7 +55,7 @@ public void setConnectionValues(GitHub github, ConnectionValues values) { GitHubUserProfile profile = github.userOperations().getUserProfile(); values.setProviderUserId(String.valueOf(profile.getId())); values.setDisplayName(profile.getLogin()); - values.setProfileUrl("https://github.com/" + profile.getLogin()); // TODO: Expose and use HTML URL + values.setProfileUrl(gitHubHost + profile.getLogin()); // TODO: Expose and use HTML URL values.setImageUrl(profile.getAvatarUrl()); } @@ -57,4 +68,8 @@ public void updateStatus(GitHub github, String message) { // not supported } + private void setGitHubHost(String gitHubHost) { + this.gitHubHost = GitHubHostUtils.getGitHubHost(gitHubHost); + } + } diff --git a/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubConnectionFactory.java b/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubConnectionFactory.java index fd53b722..3456fc28 100644 --- a/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubConnectionFactory.java +++ b/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubConnectionFactory.java @@ -33,5 +33,16 @@ public class GitHubConnectionFactory extends OAuth2ConnectionFactory { public GitHubConnectionFactory(String clientId, String clientSecret) { super("github", new GitHubServiceProvider(clientId, clientSecret), new GitHubAdapter()); } + + /** + * Creates a factory for GitHub connections. + * + * @param clientId client ID + * @param clientSecret client secret + * @param gitHubHost path for gitHubHost + */ + public GitHubConnectionFactory(String clientId, String clientSecret, String gitHubHost) { + super("github", new GitHubServiceProvider(clientId, clientSecret,gitHubHost), new GitHubAdapter(gitHubHost)); + } } diff --git a/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubHostUtils.java b/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubHostUtils.java new file mode 100644 index 00000000..9408271e --- /dev/null +++ b/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubHostUtils.java @@ -0,0 +1,46 @@ +/** + * + */ +package org.springframework.social.github.connect; + +import org.springframework.util.StringUtils; + +/** + * @author Vinayak Hulawale + * + */ +public final class GitHubHostUtils { + + private static final String GITHUB_API_VERSION = "v3"; + + private static final String API = "api"; + + private static final String HTTPS_PREFIX = "https://"; + + public static final String FORWARD_SLASH = "/"; + + public static final String DOT = "."; + + public static final String DEFAULT_GITHUB_HOST = "github.com"; + + private GitHubHostUtils() { + } + + public static String getGitHubHost(String gitHubHost) { + + return new StringBuilder(HTTPS_PREFIX) + .append(StringUtils.hasText(gitHubHost) ? gitHubHost : DEFAULT_GITHUB_HOST) + .append(GitHubHostUtils.FORWARD_SLASH).toString(); + + } + + //returns v3 API + public static String getGitHubApi(String gitHubHost) { + if (StringUtils.hasText(gitHubHost)) + return new StringBuilder(HTTPS_PREFIX).append(gitHubHost).append(GitHubHostUtils.FORWARD_SLASH) + .append(API).append(FORWARD_SLASH).append(GITHUB_API_VERSION).append(FORWARD_SLASH).toString(); + return new StringBuilder(HTTPS_PREFIX).append(API).append(DOT).append(DEFAULT_GITHUB_HOST) + .append(GitHubHostUtils.FORWARD_SLASH).toString(); + } + +} diff --git a/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubServiceProvider.java b/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubServiceProvider.java index ba6ca04e..5f2a6b03 100644 --- a/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubServiceProvider.java +++ b/spring-social-github/src/main/java/org/springframework/social/github/connect/GitHubServiceProvider.java @@ -19,25 +19,34 @@ import org.springframework.social.github.api.impl.GitHubTemplate; import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider; import org.springframework.social.oauth2.OAuth2Template; +import org.springframework.util.StringUtils; /** * Github ServiceProvider implementation. * @author Keith Donald */ public class GitHubServiceProvider extends AbstractOAuth2ServiceProvider { + + private String gitHubHost; public GitHubServiceProvider(String clientId, String clientSecret) { - super(createOAuth2Template(clientId, clientSecret)); + super(createOAuth2Template(clientId, clientSecret,null)); + } + + public GitHubServiceProvider(String clientId, String clientSecret, String gitHubHost) { + super(createOAuth2Template(clientId, clientSecret,gitHubHost)); + this.gitHubHost = gitHubHost; } - private static OAuth2Template createOAuth2Template(String clientId, String clientSecret) { - OAuth2Template oAuth2Template = new OAuth2Template(clientId, clientSecret, "https://github.com/login/oauth/authorize", "https://github.com/login/oauth/access_token"); + private static OAuth2Template createOAuth2Template(String clientId, String clientSecret, String gitHubHost) { + String host = GitHubHostUtils.getGitHubHost(gitHubHost); + OAuth2Template oAuth2Template = new OAuth2Template(clientId, clientSecret,host+"login/oauth/authorize", host+"login/oauth/access_token"); oAuth2Template.setUseParametersForClientAuthentication(true); return oAuth2Template; } public GitHub getApi(String accessToken) { - return new GitHubTemplate(accessToken); + return new GitHubTemplate(accessToken,gitHubHost); } } diff --git a/spring-social-github/src/main/java/org/springframework/social/github/security/GitHubAuthenticationService.java b/spring-social-github/src/main/java/org/springframework/social/github/security/GitHubAuthenticationService.java index 9bd9a03d..bdbf10be 100644 --- a/spring-social-github/src/main/java/org/springframework/social/github/security/GitHubAuthenticationService.java +++ b/spring-social-github/src/main/java/org/springframework/social/github/security/GitHubAuthenticationService.java @@ -24,5 +24,9 @@ public class GitHubAuthenticationService extends OAuth2AuthenticationService + + + + Optional attribute to specify custom domain for GitHub, typically used for Enterprise GitHub + + + diff --git a/spring-social-github/src/test/java/org/springframework/social/github/api/impl/GitHubApiCustomDomainTest.java b/spring-social-github/src/test/java/org/springframework/social/github/api/impl/GitHubApiCustomDomainTest.java new file mode 100644 index 00000000..5a2be65c --- /dev/null +++ b/spring-social-github/src/test/java/org/springframework/social/github/api/impl/GitHubApiCustomDomainTest.java @@ -0,0 +1,84 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.social.github.api.impl; + +import static org.junit.Assert.assertEquals; +import static org.springframework.http.HttpMethod.GET; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.social.github.api.GitHubRepo; +import org.springframework.test.web.client.MockRestServiceServer; + +/** + *

+ * Based on AbstractGitHubApiTest. + *

+ * + * @author Vinayak Hulawale + */ +public class GitHubApiCustomDomainTest { + protected GitHubTemplate gitHub; + protected GitHubTemplate unauthorizedGitHub; + protected MockRestServiceServer mockServer; + protected HttpHeaders responseHeaders; + + @Before + public void setup() { + this.gitHub = new GitHubTemplate("ACCESS_TOKEN","github.mydomain.com"); + this.mockServer = MockRestServiceServer.createServer(gitHub.getRestTemplate()); + + this.responseHeaders = new HttpHeaders(); + responseHeaders.setContentType(MediaType.APPLICATION_JSON); + + this.unauthorizedGitHub = new GitHubTemplate("github.mydomain.com"); + + // Create a mock server just to avoid hitting real GitHub if something gets past the authorization check. + MockRestServiceServer.createServer(unauthorizedGitHub.getRestTemplate()); + } + + protected Resource jsonResource(String filename) { + return new ClassPathResource(filename + ".json", getClass()); + } + + @Test + public void getRepo() { + responseHeaders.setContentType(MediaType.APPLICATION_JSON); + mockServer.expect(requestTo("https://github.mydomain.com/api/v3/repos/vinayak/project")) + .andExpect(method(GET)) + .andRespond(withSuccess(jsonResource("customDomainRepo"), MediaType.APPLICATION_JSON)); + + GitHubRepo repo = gitHub.repoOperations().getRepo("vinayak", "project"); + + // TODO There are other fields that we need to test. + assertEquals(132, repo.getId()); + assertEquals("project", repo.getName()); + assertEquals("My project", repo.getDescription()); + assertEquals("https://github.mydomain.com/api/v3/repos/vinayak/project", repo.getUrl()); + assertEquals("https://github.mydomain.com/vinayak/project", repo.getHtmlUrl()); + assertEquals("https://github.mydomain.com/vinayak/project.git", repo.getCloneUrl()); + assertEquals("git://github.mydomain.com/vinayak/project.git", repo.getGitUrl()); + assertEquals("git@github.mydomain.com:vinayak/project.git", repo.getSshUrl()); + assertEquals("https://github.mydomain.com/vinayak/project", repo.getSvnUrl()); + } +} diff --git a/spring-social-github/src/test/java/org/springframework/social/github/api/impl/customDomainRepo.json b/spring-social-github/src/test/java/org/springframework/social/github/api/impl/customDomainRepo.json new file mode 100644 index 00000000..e72b966f --- /dev/null +++ b/spring-social-github/src/test/java/org/springframework/social/github/api/impl/customDomainRepo.json @@ -0,0 +1,91 @@ +{ + "id":132, + "name":"project", + "full_name":"vinayak/project", + "owner":{ + "login":"vinayak", + "id":79, + "avatar_url":"https://gravatar.com/avatar/64f9c701d3461866d08eacf20021b2f1?d=https%3A%2F%2Fidenticons.github.com%2Fd1fe173d08e959397adf34b1d77e88d7.png&r=x", + "gravatar_id":"64f9c701d3461866d08eacf20021b2f1", + "url":"https://github.mydomain.com/api/v3/users/vinayak", + "html_url":"https://github.mydomain.com/vinayak", + "followers_url":"https://github.mydomain.com/api/v3/users/vinayak/followers", + "following_url":"https://github.mydomain.com/api/v3/users/vinayak/following{/other_user}", + "gists_url":"https://github.mydomain.com/api/v3/users/vinayak/gists{/gist_id}", + "starred_url":"https://github.mydomain.com/api/v3/users/vinayak/starred{/owner}{/repo}", + "subscriptions_url":"https://github.mydomain.com/api/v3/users/vinayak/subscriptions", + "organizations_url":"https://github.mydomain.com/api/v3/users/vinayak/orgs", + "repos_url":"https://github.mydomain.com/api/v3/users/vinayak/repos", + "events_url":"https://github.mydomain.com/api/v3/users/vinayak/events{/privacy}", + "received_events_url":"https://github.mydomain.com/api/v3/users/vinayak/received_events", + "type":"Organization", + "site_admin":false + }, + "private":false, + "html_url":"https://github.mydomain.com/vinayak/project", + "description":"My project", + "fork":false, + "url":"https://github.mydomain.com/api/v3/repos/vinayak/project", + "forks_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/forks", + "keys_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/keys{/key_id}", + "collaborators_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/collaborators{/collaborator}", + "teams_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/teams", + "hooks_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/hooks", + "issue_events_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/issues/events{/number}", + "events_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/events", + "assignees_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/assignees{/user}", + "branches_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/branches{/branch}", + "tags_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/tags", + "blobs_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/git/blobs{/sha}", + "git_tags_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/git/tags{/sha}", + "git_refs_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/git/refs{/sha}", + "trees_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/git/trees{/sha}", + "statuses_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/statuses/{sha}", + "languages_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/languages", + "stargazers_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/stargazers", + "contributors_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/contributors", + "subscribers_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/subscribers", + "subscription_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/subscription", + "commits_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/commits{/sha}", + "git_commits_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/git/commits{/sha}", + "comments_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/comments{/number}", + "issue_comment_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/issues/comments/{number}", + "contents_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/contents/{+path}", + "compare_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/compare/{base}...{head}", + "merges_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/merges", + "archive_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/{archive_format}{/ref}", + "downloads_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/downloads", + "issues_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/issues{/number}", + "pulls_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/pulls{/number}", + "milestones_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/milestones{/number}", + "notifications_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/notifications{?since,all,participating}", + "labels_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/labels{/name}", + "releases_url":"https://github.mydomain.com/api/v3/repos/vinayak/project/releases{/id}", + "created_at":"2014-02-27T10:27:38Z", + "updated_at":"2015-02-20T15:34:41Z", + "pushed_at":"2015-02-20T15:34:41Z", + "git_url":"git://github.mydomain.com/vinayak/project.git", + "ssh_url":"git@github.mydomain.com:vinayak/project.git", + "clone_url":"https://github.mydomain.com/vinayak/project.git", + "svn_url":"https://github.mydomain.com/vinayak/project", + "homepage":"", + "size":30640, + "stargazers_count":38, + "watchers_count":38, + "language":"Java", + "has_issues":true, + "has_downloads":true, + "has_wiki":true, + "forks_count":114, + "mirror_url":null, + "open_issues_count":155, + "forks":114, + "open_issues":155, + "watchers":38, + "default_branch":"master", + "permissions":{ + "admin":false, + "push":true, + "pull":true + } +} \ No newline at end of file