InlineEdit: Add DELETE /changes/<id>/edit/path%2fto%2ffile REST endpoint
Allow to delete file from change edit. Change-Id: I62ea1f3df02a2872ed51456f44fa961dfe518b37
This commit is contained in:
@@ -1247,6 +1247,28 @@ response "`204 No Content`" is returned.
|
|||||||
HTTP/1.1 204 No Content
|
HTTP/1.1 204 No Content
|
||||||
----
|
----
|
||||||
|
|
||||||
|
[[delete-edit-file]]
|
||||||
|
=== Delete file in Change Edit
|
||||||
|
--
|
||||||
|
'DELETE /changes/link:#change-id[\{change-id\}]/edit/path%2fto%2ffile'
|
||||||
|
--
|
||||||
|
|
||||||
|
Deletes a file from a change edit. This deletes the file from the repository
|
||||||
|
completely. This is not the same as reverting or restoring a file to its
|
||||||
|
previous contents.
|
||||||
|
|
||||||
|
.Request
|
||||||
|
----
|
||||||
|
DELETE /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/edit/foo HTTP/1.0
|
||||||
|
----
|
||||||
|
|
||||||
|
When change edit doesn't exist for this change yet it is created.
|
||||||
|
|
||||||
|
.Response
|
||||||
|
----
|
||||||
|
HTTP/1.1 204 No Content
|
||||||
|
----
|
||||||
|
|
||||||
[[reviewer-endpoints]]
|
[[reviewer-endpoints]]
|
||||||
== Reviewer Endpoints
|
== Reviewer Endpoints
|
||||||
|
|
||||||
|
|||||||
@@ -262,6 +262,22 @@ public class ChangeEditIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteExistingFileRest() throws Exception {
|
||||||
|
assertEquals(RefUpdate.Result.NEW,
|
||||||
|
modifier.createEdit(
|
||||||
|
change,
|
||||||
|
ps));
|
||||||
|
assertEquals(SC_NO_CONTENT, session.delete(urlEditFile()).getStatusCode());
|
||||||
|
Optional<ChangeEdit> edit = editUtil.byChange(change);
|
||||||
|
try {
|
||||||
|
fileUtil.getContent(edit.get().getChange().getProject(),
|
||||||
|
edit.get().getRevision().get(), FILE_NAME);
|
||||||
|
fail("ResourceNotFoundException expected");
|
||||||
|
} catch (ResourceNotFoundException rnfe) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void restoreDeletedFileInEdit() throws Exception {
|
public void restoreDeletedFileInEdit() throws Exception {
|
||||||
assertEquals(RefUpdate.Result.NEW,
|
assertEquals(RefUpdate.Result.NEW,
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import com.google.gerrit.extensions.registration.DynamicMap;
|
|||||||
import com.google.gerrit.extensions.restapi.AcceptsCreate;
|
import com.google.gerrit.extensions.restapi.AcceptsCreate;
|
||||||
import com.google.gerrit.extensions.restapi.AcceptsPost;
|
import com.google.gerrit.extensions.restapi.AcceptsPost;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
|
||||||
import com.google.gerrit.extensions.restapi.ChildCollection;
|
import com.google.gerrit.extensions.restapi.ChildCollection;
|
||||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||||
import com.google.gerrit.extensions.restapi.IdString;
|
import com.google.gerrit.extensions.restapi.IdString;
|
||||||
@@ -280,4 +279,35 @@ public class ChangeEdits implements
|
|||||||
return Response.none();
|
return Response.none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler to delete a file.
|
||||||
|
* <p>
|
||||||
|
* This deletes the file from the repository completely. This is not the same
|
||||||
|
* as reverting or restoring a file to its previous contents.
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
static class DeleteContent implements
|
||||||
|
RestModifyView<ChangeEditResource, DeleteContent.Input> {
|
||||||
|
public static class Input {
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ChangeEditModifier editModifier;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
DeleteContent(ChangeEditModifier editModifier) {
|
||||||
|
this.editModifier = editModifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response<?> apply(ChangeEditResource rsrc, DeleteContent.Input input)
|
||||||
|
throws AuthException, ResourceConflictException {
|
||||||
|
try {
|
||||||
|
editModifier.deleteFile(rsrc.getChangeEdit(), rsrc.getPath());
|
||||||
|
} catch(InvalidChangeOperationException | IOException e) {
|
||||||
|
throw new ResourceConflictException(e.getMessage());
|
||||||
|
}
|
||||||
|
return Response.none();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ public class Module extends RestApiModule {
|
|||||||
|
|
||||||
child(CHANGE_KIND, "edit").to(ChangeEdits.class);
|
child(CHANGE_KIND, "edit").to(ChangeEdits.class);
|
||||||
put(CHANGE_EDIT_KIND, "/").to(ChangeEdits.Put.class);
|
put(CHANGE_EDIT_KIND, "/").to(ChangeEdits.Put.class);
|
||||||
|
delete(CHANGE_EDIT_KIND).to(ChangeEdits.DeleteContent.class);
|
||||||
|
|
||||||
install(new FactoryModule() {
|
install(new FactoryModule() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user