Skip to content

Commit dfd56e4

Browse files
author
Mihail Kuznyetsov
committed
Add promise-based methods for GitHub service client
1 parent ea13a4d commit dfd56e4

2 files changed

Lines changed: 89 additions & 2 deletions

File tree

plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/GitHubClientService.java

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,21 @@ public interface GitHubClientService {
7070
* the repository name.
7171
* @param callback
7272
* callback called when operation is done.
73+
* @deprecated use {@link #getForks(String user, String repository)}
7374
*/
75+
@Deprecated
7476
void getForks(@NotNull String user, @NotNull String repository, @NotNull AsyncRequestCallback<GitHubRepositoryList> callback);
7577

78+
/**
79+
* Get list of forks for given repository
80+
*
81+
* @param user
82+
* the owner of the repository.
83+
* @param repository
84+
* the repository name.
85+
*/
86+
Promise<GitHubRepositoryList> getForks(String user, String repository);
87+
7688
/**
7789
* Fork the given repository for the authorized user.
7890
*
@@ -82,9 +94,21 @@ public interface GitHubClientService {
8294
* the repository name.
8395
* @param callback
8496
* callback called when operation is done.
97+
* @deprecated use {@link #fork(String, String)}
8598
*/
99+
@Deprecated
86100
void fork(@NotNull String user, @NotNull String repository, @NotNull AsyncRequestCallback<GitHubRepository> callback);
87101

102+
/**
103+
* Fork the given repository for the authorized user.
104+
*
105+
* @param user
106+
* the owner of the repository to fork.
107+
* @param repository
108+
* the repository name.
109+
*/
110+
Promise<GitHubRepository> fork(String user, String repository);
111+
88112
/**
89113
* Add a comment to the issue on the given repository.
90114
*
@@ -111,9 +135,21 @@ void commentIssue(@NotNull String user, @NotNull String repository, @NotNull Str
111135
* the repository name.
112136
* @param callback
113137
* callback called when operation is done.
138+
* @deprecated use {@link #getPullRequests(String, String)}
114139
*/
140+
@Deprecated
115141
void getPullRequests(@NotNull String owner, @NotNull String repository, @NotNull AsyncRequestCallback<GitHubPullRequestList> callback);
116142

143+
/**
144+
* Get pull requests for given repository.
145+
*
146+
* @param owner
147+
* the repository owner.
148+
* @param repository
149+
* the repository name.
150+
*/
151+
Promise<GitHubPullRequestList> getPullRequests(@NotNull String owner, @NotNull String repository);
152+
117153
/**
118154
* Get a pull request by id for a given repository.
119155
*
@@ -142,10 +178,28 @@ void getPullRequest(@NotNull String owner,
142178
* the pull request information.
143179
* @param callback
144180
* callback called when operation is done.
181+
* @deprecated use {@link #createPullRequest(String, String, GitHubPullRequestCreationInput)}
145182
*/
146-
void createPullRequest(@NotNull String user, @NotNull String repository, @NotNull GitHubPullRequestCreationInput input,
183+
@Deprecated
184+
void createPullRequest(@NotNull String user,
185+
@NotNull String repository,
186+
@NotNull GitHubPullRequestCreationInput input,
147187
@NotNull AsyncRequestCallback<GitHubPullRequest> callback);
148188

189+
/**
190+
* Create a pull request on origin repository
191+
*
192+
* @param user
193+
* the owner of the repository.
194+
* @param repository
195+
* the repository name.
196+
* @param input
197+
* the pull request information.
198+
*/
199+
Promise<GitHubPullRequest> createPullRequest(@NotNull String user,
200+
@NotNull String repository,
201+
@NotNull GitHubPullRequestCreationInput input);
202+
149203
/**
150204
* Get the list of available public repositories for a GitHub user.
151205
*

plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/client/GitHubClientServiceImpl.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,34 @@ public Promise<List<GitHubRepository>> getRepositoriesList() {
9999

100100
/** {@inheritDoc} */
101101
@Override
102-
public void getForks(@NotNull String user, @NotNull String repository,
102+
public void getForks(@NotNull String user,
103+
@NotNull String repository,
103104
@NotNull AsyncRequestCallback<GitHubRepositoryList> callback) {
104105
String url = baseUrl + FORKS + "/" + user + "/" + repository;
105106
asyncRequestFactory.createGetRequest(url).loader(loader).send(callback);
106107
}
107108

109+
@Override
110+
public Promise<GitHubRepositoryList> getForks(String user, String repository) {
111+
return asyncRequestFactory.createGetRequest(baseUrl + FORKS + '/' + user + '/' + repository)
112+
.loader(loader)
113+
.send(dtoUnmarshallerFactory.newUnmarshaller(GitHubRepositoryList.class));
114+
}
115+
108116
/** {@inheritDoc} */
109117
@Override
110118
public void fork(@NotNull String user, @NotNull String repository, @NotNull AsyncRequestCallback<GitHubRepository> callback) {
111119
String url = baseUrl + CREATE_FORK + "/" + user + "/" + repository;
112120
asyncRequestFactory.createGetRequest(url).loader(loader).send(callback);
113121
}
114122

123+
@Override
124+
public Promise<GitHubRepository> fork(String user, String repository) {
125+
return asyncRequestFactory.createGetRequest(baseUrl + CREATE_FORK + '/' + user + '/' + repository)
126+
.loader(loader)
127+
.send(dtoUnmarshallerFactory.newUnmarshaller(GitHubRepository.class));
128+
}
129+
115130
@Override
116131
public void commentIssue(@NotNull String user, @NotNull String repository, @NotNull String issue,
117132
@NotNull GitHubIssueCommentInput input, @NotNull AsyncRequestCallback<GitHubIssueComment> callback) {
@@ -126,6 +141,14 @@ public void getPullRequests(@NotNull String owner, @NotNull String repository,
126141
asyncRequestFactory.createGetRequest(url).loader(loader).send(callback);
127142
}
128143

144+
@Override
145+
public Promise<GitHubPullRequestList> getPullRequests(@NotNull String owner, @NotNull String repository) {
146+
final String url = baseUrl + PULL_REQUESTS + '/' + owner + '/' + repository;
147+
return asyncRequestFactory.createGetRequest(url)
148+
.loader(loader)
149+
.send(dtoUnmarshallerFactory.newUnmarshaller(GitHubPullRequestList.class));
150+
}
151+
129152
@Override
130153
public void getPullRequest(final String owner, final String repository, final String pullRequestId,
131154
final AsyncRequestCallback<GitHubPullRequest> callback) {
@@ -141,6 +164,16 @@ public void createPullRequest(@NotNull String user, @NotNull String repository,
141164
asyncRequestFactory.createPostRequest(url, input).loader(loader).send(callback);
142165
}
143166

167+
@Override
168+
public Promise<GitHubPullRequest> createPullRequest(@NotNull String user,
169+
@NotNull String repository,
170+
@NotNull GitHubPullRequestCreationInput input) {
171+
final String url = baseUrl + PULL_REQUEST + '/' + user + '/' + repository;
172+
return asyncRequestFactory.createPostRequest(url, input)
173+
.loader(loader)
174+
.send(dtoUnmarshallerFactory.newUnmarshaller(GitHubPullRequest.class));
175+
}
176+
144177
/** {@inheritDoc} */
145178
@Override
146179
public void getRepositoriesByUser(String userName, @NotNull AsyncRequestCallback<GitHubRepositoryList> callback) {

0 commit comments

Comments
 (0)