diff options
author | Kevin Sawicki | 2012-06-06 17:01:43 +0000 |
---|---|---|
committer | Kevin Sawicki | 2012-06-06 17:01:43 +0000 |
commit | 3dbb4dd7e04e56da8fb8f46e0b1047a7225623c5 (patch) | |
tree | b68f1d191c65914ee275fa0cea99215a7c5e5c64 | |
parent | aa1af9f2743923d258fb41cace54f4c9810e8b19 (diff) | |
download | egit-github-3dbb4dd7e04e56da8fb8f46e0b1047a7225623c5.tar.gz egit-github-3dbb4dd7e04e56da8fb8f46e0b1047a7225623c5.tar.xz egit-github-3dbb4dd7e04e56da8fb8f46e0b1047a7225623c5.zip |
Use API v3 endpoint for repository search API
API v2 is being removed and is now provided as a
legacy v3 API.
Change-Id: Id1dea03486893b25012ae72518910a7d1bb3f4b9
6 files changed, 25 insertions, 69 deletions
diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GitHubClientTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GitHubClientTest.java index 17e29140..f0a2e379 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GitHubClientTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/GitHubClientTest.java @@ -33,18 +33,6 @@ public class GitHubClientTest { } /** - * Verify prefix with API v2 host - */ - @Test - public void prefixHostApiV2() { - PrefixClient client = new PrefixClient(IGitHubConstants.HOST_API_V2); - assertEquals("/api/v3/repos/o/n", client.uri("/api/v3/repos/o/n")); - assertEquals("/repos/o/n", client.uri("/repos/o/n")); - assertEquals("/api/v2/json/repos/search/test", - client.uri("/api/v2/json/repos/search/test")); - } - - /** * Verify prefix with API v3 host */ @Test @@ -64,7 +52,5 @@ public class GitHubClientTest { PrefixClient client = new PrefixClient("localhost"); assertEquals("/api/v3/repos/o/n", client.uri("/repos/o/n")); assertEquals("/api/v3/repos/o/n", client.uri("/api/v3/repos/o/n")); - assertEquals("/api/v2/json/repos/search/test", - client.uri("/api/v2/json/repos/search/test")); } } diff --git a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java index d60c3ef3..d4b76d25 100644 --- a/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java +++ b/org.eclipse.egit.github.core.tests/src/org/eclipse/egit/github/core/tests/RepositoryServiceTest.java @@ -379,7 +379,7 @@ public class RepositoryServiceTest { public void searchRepositories() throws IOException { service.searchRepositories("test"); GitHubRequest request = new GitHubRequest(); - request.setUri(Utils.page("/api/v2/json/repos/search/test")); + request.setUri(Utils.page("/legacy/repos/search/test")); verify(client).get(request); } @@ -392,8 +392,7 @@ public class RepositoryServiceTest { public void searchRepositoriesMatchingLanguage() throws IOException { service.searchRepositories("buffers", "c"); GitHubRequest request = new GitHubRequest(); - request.setUri(Utils - .page("/api/v2/json/repos/search/buffers?language=c")); + request.setUri(Utils.page("/legacy/repos/search/buffers?language=c")); verify(client).get(request); } @@ -406,8 +405,7 @@ public class RepositoryServiceTest { public void searchRepositoriesStartingAtPage() throws IOException { service.searchRepositories("buffers", 50); GitHubRequest request = new GitHubRequest(); - request.setUri(Utils - .page("/api/v2/json/repos/search/buffers?start_page=50")); + request.setUri(Utils.page("/legacy/repos/search/buffers?start_page=50")); verify(client).get(request); } @@ -420,7 +418,7 @@ public class RepositoryServiceTest { public void searchEscaped() throws IOException { service.searchRepositories("a and a."); GitHubRequest request = new GitHubRequest(); - request.setUri(Utils.page("/api/v2/json/repos/search/a%20and%20a%2E")); + request.setUri(Utils.page("/legacy/repos/search/a%20and%20a%2E")); verify(client).get(request); } diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java index 99340ea0..5e992129 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java @@ -26,11 +26,9 @@ import static org.eclipse.egit.github.core.client.IGitHubConstants.AUTH_TOKEN; import static org.eclipse.egit.github.core.client.IGitHubConstants.CHARSET_UTF8; import static org.eclipse.egit.github.core.client.IGitHubConstants.CONTENT_TYPE_JSON; import static org.eclipse.egit.github.core.client.IGitHubConstants.HOST_API; -import static org.eclipse.egit.github.core.client.IGitHubConstants.HOST_API_V2; import static org.eclipse.egit.github.core.client.IGitHubConstants.HOST_DEFAULT; import static org.eclipse.egit.github.core.client.IGitHubConstants.HOST_GISTS; import static org.eclipse.egit.github.core.client.IGitHubConstants.PROTOCOL_HTTPS; -import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_V2_API; import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_V3_API; import com.google.gson.Gson; @@ -184,7 +182,7 @@ public class GitHubClient { baseUri = uri.toString(); // Use URI prefix on non-standard host names - if (HOST_API.equals(hostname) || HOST_API_V2.equals(hostname)) + if (HOST_API.equals(hostname)) prefix = null; else prefix = SEGMENT_V3_API; @@ -239,10 +237,10 @@ public class GitHubClient { * @return configured URI */ protected String configureUri(final String uri) { - if (prefix == null || uri.startsWith(SEGMENT_V2_API) - || uri.startsWith(prefix)) + if (prefix == null || uri.startsWith(prefix)) return uri; - return prefix + uri; + else + return prefix + uri; } /** diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java index 575a5ca9..62cabd83 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/IGitHubConstants.java @@ -42,8 +42,6 @@ public interface IGitHubConstants { /** */ String HOST_API = "api.github.com"; //$NON-NLS-1$ /** */ - String HOST_API_V2 = "github.com"; //$NON-NLS-1$ - /** */ String HOST_DEFAULT = "github.com"; //$NON-NLS-1$ /** */ String HOST_GISTS = "gist.github.com"; //$NON-NLS-1$ @@ -121,6 +119,8 @@ public interface IGitHubConstants { /** */ String SEGMENT_LABELS = "/labels"; //$NON-NLS-1$ /** */ + String SEGMENT_LEGACY = "/legacy"; //$NON-NLS-1$ + /** */ String SEGMENT_LANGUAGES = "/languages"; //$NON-NLS-1$ /** */ String SEGMENT_MEMBERS = "/members"; //$NON-NLS-1$ @@ -173,8 +173,6 @@ public interface IGitHubConstants { /** */ String SEGMENT_WATCHERS = "/watchers"; //$NON-NLS-1$ /** */ - String SEGMENT_V2_API = "/api/v2/json"; //$NON-NLS-1$ - /** */ String SEGMENT_V3_API = "/api/v3"; //$NON-NLS-1$ /** */ @@ -185,6 +183,4 @@ public interface IGitHubConstants { /** */ String URL_API = PROTOCOL_HTTPS + "://" + HOST_API; //$NON-NLS-1$ - /** */ - String URL_API_V2 = PROTOCOL_HTTPS + "://" + HOST_API_V2; //$NON-NLS-1$ } diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java index 75817acc..d74e091c 100644 --- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java +++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/service/RepositoryService.java @@ -18,6 +18,7 @@ import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_CONTR import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_FORKS; import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_HOOKS; import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_LANGUAGES; +import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_LEGACY; import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_ORGS; import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_REPOS; import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_SEARCH; @@ -25,7 +26,6 @@ import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_TAGS; import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_TEST; import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_USER; import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_USERS; -import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_V2_API; import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_FIRST; import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_SIZE; @@ -402,9 +402,6 @@ public class RepositoryService extends GitHubService { /** * Search for repositories matching query. - * <p> - * This method requires an API v2 configured {@link GitHubClient} as it is - * not yet supported in API v3 clients. * * @param query * @return list of repositories @@ -417,9 +414,6 @@ public class RepositoryService extends GitHubService { /** * Search for repositories matching query. - * <p> - * This method requires an API v2 configured {@link GitHubClient} as it is - * not yet supported in API v3 clients. * * @param query * @param startPage @@ -433,9 +427,6 @@ public class RepositoryService extends GitHubService { /** * Search for repositories matching language and query. - * <p> - * This method requires an API v2 configured {@link GitHubClient} as it is - * not yet supported in API v3 clients. * * @param query * @param language @@ -449,9 +440,6 @@ public class RepositoryService extends GitHubService { /** * Search for repositories matching language and query. - * <p> - * This method requires an API v2 configured {@link GitHubClient} as it is - * not yet supported in API v3 clients. * * @param query * @param language @@ -466,9 +454,8 @@ public class RepositoryService extends GitHubService { if (query.length() == 0) throw new IllegalArgumentException("Query cannot be empty"); //$NON-NLS-1$ - StringBuilder uri = new StringBuilder(SEGMENT_V2_API); - uri.append(SEGMENT_REPOS); - uri.append(SEGMENT_SEARCH); + StringBuilder uri = new StringBuilder(SEGMENT_LEGACY + SEGMENT_REPOS + + SEGMENT_SEARCH); final String encodedQuery = URLEncoder.encode(query, CHARSET_UTF8) .replace("+", "%20") //$NON-NLS-1$ //$NON-NLS-2$ .replace(".", "%2E"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -491,9 +478,6 @@ public class RepositoryService extends GitHubService { /** * Search for repositories matching search parameters. - * <p> - * This method requires an API v2 configured {@link GitHubClient} as it is - * not yet supported in API v3 clients. * * @param params * @return list of repositories @@ -506,9 +490,6 @@ public class RepositoryService extends GitHubService { /** * Search for repositories matching search parameters. - * <p> - * This method requires an API v2 configured {@link GitHubClient} as it is - * not yet supported in API v3 clients. * * @param queryParams * @param startPage diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySearchWizardPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySearchWizardPage.java index fe92cf35..8cf00ca6 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySearchWizardPage.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySearchWizardPage.java @@ -20,8 +20,6 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.egit.github.core.Language; import org.eclipse.egit.github.core.Repository; import org.eclipse.egit.github.core.SearchRepository; -import org.eclipse.egit.github.core.client.GitHubClient; -import org.eclipse.egit.github.core.client.IGitHubConstants; import org.eclipse.egit.github.core.service.RepositoryService; import org.eclipse.egit.github.core.util.UrlUtils; import org.eclipse.egit.ui.UIIcons; @@ -62,15 +60,12 @@ import org.eclipse.ui.PlatformUI; * Search for GitHub repositories wizard page. */ @SuppressWarnings("restriction") -public class RepositorySearchWizardPage extends WizardPage implements IRepositorySearchResult { +public class RepositorySearchWizardPage extends WizardPage implements + IRepositorySearchResult { private SearchRepository[] repositories = null; - private final GitHubClient client = new GitHubClient( - IGitHubConstants.HOST_API_V2, -1, IGitHubConstants.PROTOCOL_HTTPS); - - private final RepositoryService repositoryService = new RepositoryService( - client); + private final RepositoryService repositoryService; private Text searchText; @@ -81,11 +76,14 @@ public class RepositorySearchWizardPage extends WizardPage implements IRepositor super("repoSearchPage", Messages.RepositorySearchWizardPage_Title, null); //$NON-NLS-1$ setDescription(Messages.RepositorySearchWizardPage_Description); setPageComplete(false); + + repositoryService = new RepositoryService(); + GitHub.configureClient(repositoryService.getClient()); } /** * Get selected repositories - * + * * @return repositories */ protected SearchRepository[] getRepositories() { @@ -93,7 +91,7 @@ public class RepositorySearchWizardPage extends WizardPage implements IRepositor } /** - * + * */ public void createControl(Composite parent) { final Composite root = new Composite(parent, SWT.NONE); @@ -292,13 +290,12 @@ public class RepositorySearchWizardPage extends WizardPage implements IRepositor } } - public GitRepositoryInfo getGitRepositoryInfo() throws NoRepositoryInfoException { - GitHubClient client = GitHub - .configureClient(new GitHubClient()); - RepositoryService service = new RepositoryService(client); + public GitRepositoryInfo getGitRepositoryInfo() + throws NoRepositoryInfoException { String cloneUrl = null; try { - Repository fullRepo = service.getRepository(repositories[0]); + Repository fullRepo = repositoryService + .getRepository(repositories[0]); cloneUrl = fullRepo.getCloneUrl(); } catch (IOException e) { throw new NoRepositoryInfoException(e.getMessage(), e); |