From dfd56e437f17447e257816f2caeb468be0dece37 Mon Sep 17 00:00:00 2001 From: Mihail Kuznyetsov Date: Thu, 3 Mar 2016 14:02:09 +0200 Subject: [PATCH] Add promise-based methods for GitHub service client --- .../github/client/GitHubClientService.java | 56 ++++++++++++++++++- .../client/GitHubClientServiceImpl.java | 35 +++++++++++- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/GitHubClientService.java b/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/GitHubClientService.java index 521d3a3276..efc455924c 100644 --- a/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/GitHubClientService.java +++ b/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/GitHubClientService.java @@ -70,9 +70,21 @@ public interface GitHubClientService { * the repository name. * @param callback * callback called when operation is done. + * @deprecated use {@link #getForks(String user, String repository)} */ + @Deprecated void getForks(@NotNull String user, @NotNull String repository, @NotNull AsyncRequestCallback callback); + /** + * Get list of forks for given repository + * + * @param user + * the owner of the repository. + * @param repository + * the repository name. + */ + Promise getForks(String user, String repository); + /** * Fork the given repository for the authorized user. * @@ -82,9 +94,21 @@ public interface GitHubClientService { * the repository name. * @param callback * callback called when operation is done. + * @deprecated use {@link #fork(String, String)} */ + @Deprecated void fork(@NotNull String user, @NotNull String repository, @NotNull AsyncRequestCallback callback); + /** + * Fork the given repository for the authorized user. + * + * @param user + * the owner of the repository to fork. + * @param repository + * the repository name. + */ + Promise fork(String user, String repository); + /** * Add a comment to the issue on the given repository. * @@ -111,9 +135,21 @@ public interface GitHubClientService { * the repository name. * @param callback * callback called when operation is done. + * @deprecated use {@link #getPullRequests(String, String)} */ + @Deprecated void getPullRequests(@NotNull String owner, @NotNull String repository, @NotNull AsyncRequestCallback callback); + /** + * Get pull requests for given repository. + * + * @param owner + * the repository owner. + * @param repository + * the repository name. + */ + Promise getPullRequests(@NotNull String owner, @NotNull String repository); + /** * Get a pull request by id for a given repository. * @@ -142,10 +178,28 @@ public interface GitHubClientService { * the pull request information. * @param callback * callback called when operation is done. + * @deprecated use {@link #createPullRequest(String, String, GitHubPullRequestCreationInput)} */ - void createPullRequest(@NotNull String user, @NotNull String repository, @NotNull GitHubPullRequestCreationInput input, + @Deprecated + void createPullRequest(@NotNull String user, + @NotNull String repository, + @NotNull GitHubPullRequestCreationInput input, @NotNull AsyncRequestCallback callback); + /** + * Create a pull request on origin repository + * + * @param user + * the owner of the repository. + * @param repository + * the repository name. + * @param input + * the pull request information. + */ + Promise createPullRequest(@NotNull String user, + @NotNull String repository, + @NotNull GitHubPullRequestCreationInput input); + /** * Get the list of available public repositories for a GitHub user. * diff --git a/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/GitHubClientServiceImpl.java b/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/GitHubClientServiceImpl.java index 4ce32ed5e4..29bd794c56 100644 --- a/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/GitHubClientServiceImpl.java +++ b/plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/GitHubClientServiceImpl.java @@ -99,12 +99,20 @@ public class GitHubClientServiceImpl implements GitHubClientService { /** {@inheritDoc} */ @Override - public void getForks(@NotNull String user, @NotNull String repository, + public void getForks(@NotNull String user, + @NotNull String repository, @NotNull AsyncRequestCallback callback) { String url = baseUrl + FORKS + "/" + user + "/" + repository; asyncRequestFactory.createGetRequest(url).loader(loader).send(callback); } + @Override + public Promise getForks(String user, String repository) { + return asyncRequestFactory.createGetRequest(baseUrl + FORKS + '/' + user + '/' + repository) + .loader(loader) + .send(dtoUnmarshallerFactory.newUnmarshaller(GitHubRepositoryList.class)); + } + /** {@inheritDoc} */ @Override public void fork(@NotNull String user, @NotNull String repository, @NotNull AsyncRequestCallback callback) { @@ -112,6 +120,13 @@ public class GitHubClientServiceImpl implements GitHubClientService { asyncRequestFactory.createGetRequest(url).loader(loader).send(callback); } + @Override + public Promise fork(String user, String repository) { + return asyncRequestFactory.createGetRequest(baseUrl + CREATE_FORK + '/' + user + '/' + repository) + .loader(loader) + .send(dtoUnmarshallerFactory.newUnmarshaller(GitHubRepository.class)); + } + @Override public void commentIssue(@NotNull String user, @NotNull String repository, @NotNull String issue, @NotNull GitHubIssueCommentInput input, @NotNull AsyncRequestCallback callback) { @@ -126,6 +141,14 @@ public class GitHubClientServiceImpl implements GitHubClientService { asyncRequestFactory.createGetRequest(url).loader(loader).send(callback); } + @Override + public Promise getPullRequests(@NotNull String owner, @NotNull String repository) { + final String url = baseUrl + PULL_REQUESTS + '/' + owner + '/' + repository; + return asyncRequestFactory.createGetRequest(url) + .loader(loader) + .send(dtoUnmarshallerFactory.newUnmarshaller(GitHubPullRequestList.class)); + } + @Override public void getPullRequest(final String owner, final String repository, final String pullRequestId, final AsyncRequestCallback callback) { @@ -141,6 +164,16 @@ public class GitHubClientServiceImpl implements GitHubClientService { asyncRequestFactory.createPostRequest(url, input).loader(loader).send(callback); } + @Override + public Promise createPullRequest(@NotNull String user, + @NotNull String repository, + @NotNull GitHubPullRequestCreationInput input) { + final String url = baseUrl + PULL_REQUEST + '/' + user + '/' + repository; + return asyncRequestFactory.createPostRequest(url, input) + .loader(loader) + .send(dtoUnmarshallerFactory.newUnmarshaller(GitHubPullRequest.class)); + } + /** {@inheritDoc} */ @Override public void getRepositoriesByUser(String userName, @NotNull AsyncRequestCallback callback) {