Skip to content

Commit 374663e

Browse files
committed
CODENVY-191: Add client and implementation for factory update and github pull request update
1 parent 97e3f01 commit 374663e

9 files changed

Lines changed: 142 additions & 3 deletions

File tree

core/platform-api-client-gwt/che-core-client-gwt-factory/src/main/java/org/eclipse/che/api/factory/gwt/client/FactoryServiceClient.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public interface FactoryServiceClient {
6161
void getFactoryJson(@NotNull String workspaceId, @NotNull String path, @NotNull AsyncRequestCallback<Factory> callback);
6262

6363
/**
64-
* Save factory to storage.
64+
* Get factory as JSON.
6565
*
6666
* @param workspaceId
6767
* workspace id
@@ -90,4 +90,15 @@ public interface FactoryServiceClient {
9090
* @return a promise that will provide a list of {@link Factory}s, or rejects with an error
9191
*/
9292
Promise<List<Factory>> findFactory(Integer skipCount, Integer maxItems, List<Pair<String, String>> params);
93+
94+
/**
95+
* Updates factory by id
96+
*
97+
* @param id
98+
* factory identifier
99+
* @param factory
100+
* update body
101+
* @return updated factory
102+
*/
103+
Promise<Factory> updateFactory(String id, Factory factory);
93104
}

core/platform-api-client-gwt/che-core-client-gwt-factory/src/main/java/org/eclipse/che/api/factory/gwt/client/FactoryServiceClientImpl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package org.eclipse.che.api.factory.gwt.client;
1212

1313
import com.google.common.base.Joiner;
14+
import com.google.gwt.http.client.RequestBuilder;
1415
import com.google.inject.Inject;
1516
import com.google.inject.Singleton;
1617

@@ -85,7 +86,7 @@ public void getFactoryJson(String workspaceId, String path, AsyncRequestCallback
8586
}
8687
asyncRequestFactory.createGetRequest(url.toString())
8788
.header(HTTPHeader.ACCEPT, MimeType.APPLICATION_JSON)
88-
.loader(loaderFactory.newLoader("Getting info about factory..."))
89+
.loader(loaderFactory.newLoader("Getting info about factory..."))
8990
.send(callback);
9091
}
9192

@@ -132,6 +133,14 @@ public Promise<List<Factory>> findFactory(@Nullable Integer skipCount,
132133
.send(unmarshallerFactory.newListUnmarshaller(Factory.class));
133134
}
134135

136+
@Override
137+
public Promise<Factory> updateFactory(String id, Factory factory) {
138+
return asyncRequestFactory.createRequest(RequestBuilder.PUT, API_FACTORY_BASE_URL + id, factory, false)
139+
.header(HTTPHeader.CONTENT_TYPE, MimeType.APPLICATION_JSON)
140+
.loader(loaderFactory.newLoader("Updating factory..."))
141+
.send(unmarshallerFactory.newUnmarshaller(Factory.class));
142+
}
143+
135144
/**
136145
* Forms the query string from collection of query params
137146
*

core/platform-api-client-gwt/che-core-client-gwt-git/src/main/java/org/eclipse/che/api/git/gwt/client/GitServiceClient.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,36 @@ void pull(String workspaceId,
350350
* @param callback
351351
* callback
352352
* @throws WebSocketException
353+
* @deprecated use {@link #push(String, ProjectConfigDto, List, String , boolean)}
353354
*/
355+
@Deprecated
354356
void push(String workspaceId,
355357
ProjectConfigDto project,
356358
List<String> refSpec,
357359
String remote, boolean force,
358360
AsyncRequestCallback<PushResponse> callback);
359361

362+
363+
/**
364+
* Push changes from local repository to remote one (sends request over WebSocket).
365+
*
366+
* @param wsId
367+
* id of current workspace
368+
* @param project
369+
* project
370+
* @param refSpec
371+
* list of refspec to push
372+
* @param remote
373+
* remote repository name or url
374+
* @param force
375+
* push refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. If <code>true</code>
376+
* disables the check. This can cause the remote repository to lose commits
377+
*/
378+
Promise<PushResponse> push(String wsId,
379+
ProjectConfigDto project,
380+
List<String> refSpec,
381+
String remote,
382+
boolean force);
360383
/**
361384
* Clones one remote repository to local one (over WebSocket).
362385
*

core/platform-api-client-gwt/che-core-client-gwt-git/src/main/java/org/eclipse/che/api/git/gwt/client/GitServiceClientImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,16 @@ public void push(String workspaceId,
288288
asyncRequestFactory.createPostRequest(url, pushRequest).send(callback);
289289
}
290290

291+
@Override
292+
public Promise<PushResponse> push(String wsId, ProjectConfigDto project, List<String> refSpec, String remote, boolean force) {
293+
PushRequest pushRequest = dtoFactory.createDto(PushRequest.class)
294+
.withRemote(remote)
295+
.withRefSpec(refSpec)
296+
.withForce(force);
297+
return asyncRequestFactory.createPostRequest(extPath + "/git/" + wsId + PUSH + "?projectPath=" + project.getPath(), pushRequest)
298+
.send(dtoUnmarshallerFactory.newUnmarshaller(PushResponse.class));
299+
}
300+
291301
/** {@inheritDoc} */
292302
@Override
293303
public void remoteList(String workspaceId,

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,22 @@ Promise<GitHubPullRequest> createPullRequest(@NotNull String user,
275275
* callback called when operation is done.
276276
*/
277277
void updatePublicKey(@NotNull AsyncRequestCallback<Void> callback);
278-
}
278+
279+
/**
280+
* Updates github pull request
281+
*
282+
* @param user
283+
* repository owner
284+
* @param repository
285+
* name of repository
286+
* @param pullRequestId
287+
* pull request identifier
288+
* @param pullRequest
289+
* update body
290+
* @return updated pull request
291+
*/
292+
Promise<GitHubPullRequest> updatePullRequest(String user,
293+
String repository,
294+
String pullRequestId,
295+
GitHubPullRequest pullRequest);
296+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*******************************************************************************/
1111
package org.eclipse.che.ide.ext.github.client;
1212

13+
import com.google.gwt.http.client.RequestBuilder;
1314
import com.google.inject.Inject;
1415
import com.google.inject.Singleton;
1516

@@ -240,4 +241,15 @@ public void updatePublicKey(@NotNull AsyncRequestCallback<Void> callback) {
240241
String url = baseUrl + SSH_GEN;
241242
asyncRequestFactory.createPostRequest(url, null).loader(loader).send(callback);
242243
}
244+
245+
@Override
246+
public Promise<GitHubPullRequest> updatePullRequest(String owner,
247+
String repository,
248+
String pullRequestId,
249+
GitHubPullRequest updateInput) {
250+
final String url = baseUrl + PULL_REQUEST + '/' + owner + '/' + repository + '/' + pullRequestId;
251+
return asyncRequestFactory.createRequest(RequestBuilder.PUT, url, updateInput, false)
252+
.loader(loader)
253+
.send(dtoUnmarshallerFactory.newUnmarshaller(GitHubPullRequest.class));
254+
}
243255
}

plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/server/GitHubDTOFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ public GitHubPullRequest createPullRequest(GHPullRequest ghPullRequest) throws I
177177
dtoPullRequest.setState(ghPullRequest.getState().toString());
178178
dtoPullRequest.setHead(createPullRequestHead(ghPullRequest.getHead()));
179179
dtoPullRequest.setMerged(ghPullRequest.isMerged());
180+
dtoPullRequest.setBody(ghPullRequest.getBody());
181+
dtoPullRequest.setTitle(ghPullRequest.getTitle());
180182
if (ghPullRequest.getMergedBy() != null) {
181183
dtoPullRequest.setMergedBy(createUser(ghPullRequest.getMergedBy()));
182184
}

plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/server/rest/GitHubService.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.eclipse.che.api.core.ApiException;
1414
import org.eclipse.che.api.core.NotFoundException;
1515
import org.eclipse.che.api.core.ServerException;
16+
import org.eclipse.che.api.core.UnauthorizedException;
1617
import org.eclipse.che.api.git.GitException;
1718
import org.eclipse.che.api.ssh.server.SshServiceClient;
1819
import org.eclipse.che.api.ssh.shared.dto.GenerateSshPairRequest;
@@ -38,6 +39,7 @@
3839
import javax.inject.Inject;
3940
import javax.ws.rs.GET;
4041
import javax.ws.rs.POST;
42+
import javax.ws.rs.PUT;
4143
import javax.ws.rs.Path;
4244
import javax.ws.rs.PathParam;
4345
import javax.ws.rs.Produces;
@@ -233,6 +235,36 @@ public GitHubPullRequest createPullRequest(@PathParam("user") String user, @Path
233235
}
234236
}
235237

238+
@PUT
239+
@Path("pullrequest/{user}/{repository}/{pullRequestId}")
240+
@Produces(MediaType.APPLICATION_JSON)
241+
public GitHubPullRequest updatePullRequest(@PathParam("user")
242+
String user,
243+
@PathParam("repository")
244+
String repository,
245+
@PathParam("pullRequestId")
246+
String pullRequestId,
247+
GitHubPullRequest pullRequest) throws ServerException,
248+
UnauthorizedException {
249+
try {
250+
final GHPullRequest ghPullRequest = gitHubFactory.connect()
251+
.getUser(user)
252+
.getRepository(repository)
253+
.getPullRequest(Integer.valueOf(pullRequestId));
254+
final String body = pullRequest.getBody();
255+
if (body != null && !body.equals(ghPullRequest.getBody())) {
256+
ghPullRequest.setBody(body);
257+
}
258+
final String title = pullRequest.getTitle();
259+
if (title != null && !title.equals(ghPullRequest.getTitle())) {
260+
ghPullRequest.setTitle(title);
261+
}
262+
return gitHubDTOFactory.createPullRequest(ghPullRequest);
263+
} catch (IOException ioEx) {
264+
throw new ServerException(ioEx.getMessage());
265+
}
266+
}
267+
236268
@GET
237269
@Path("orgs")
238270
@Produces(MediaType.APPLICATION_JSON)

plugins/plugin-github/che-plugin-github-ext-github/src/main/java/org/eclipse/che/ide/ext/github/shared/GitHubPullRequest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,26 @@ public interface GitHubPullRequest {
112112
void setMergeable(boolean mergeable);
113113

114114
GitHubPullRequest withMergeable(boolean mergeable);
115+
116+
/**
117+
* Get pull request body.
118+
*
119+
* @return {@link String} body
120+
*/
121+
String getBody();
122+
123+
void setBody(String body);
124+
125+
GitHubPullRequest withBody(String body);
126+
127+
/**
128+
* Get pull request title.
129+
*
130+
* @return {@link String} title
131+
*/
132+
String getTitle();
133+
134+
void setTitle(String title);
135+
136+
GitHubPullRequest withTitle(String title);
115137
}

0 commit comments

Comments
 (0)