InlineEdit: Extend POST changes/<id>/edit endpoint to rename files
Change-Id: I702911b6ab5cec06e8d570d6dc196362e9e7e77e
This commit is contained in:

committed by
David Pursehouse

parent
2d142b11c1
commit
a00c953a44
@@ -1317,14 +1317,15 @@ content isn't provided, it is wiped out for that file. As response
|
||||
----
|
||||
|
||||
[[post-edit]]
|
||||
=== Restore file content in Change Edit
|
||||
=== Restore file content or rename files in Change Edit
|
||||
--
|
||||
'POST /changes/link:#change-id[\{change-id\}]/edit
|
||||
--
|
||||
|
||||
Creates empty change edit or restores file content in change edit. The
|
||||
request body needs to include a link:#change-edit-input[ChangeEditInput]
|
||||
entity when a file within change edit should be restored.
|
||||
Creates empty change edit, restores file content or renames files in change
|
||||
edit. The request body needs to include a
|
||||
link:#change-edit-input[ChangeEditInput] entity when a file within change
|
||||
edit should be restored or old and new file names to rename a file.
|
||||
|
||||
.Request
|
||||
----
|
||||
@@ -1336,9 +1337,23 @@ entity when a file within change edit should be restored.
|
||||
}
|
||||
----
|
||||
|
||||
or for rename:
|
||||
|
||||
.Request
|
||||
----
|
||||
POST /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/edit HTTP/1.0
|
||||
Content-Type: application/json; charset=UTF-8
|
||||
|
||||
{
|
||||
"old_path": "foo",
|
||||
"new_path": "bar"
|
||||
}
|
||||
----
|
||||
|
||||
When change edit doesn't exist for this change yet it is created. When path
|
||||
and restore flag are provided in request body, this file is restored. As
|
||||
response "`204 No Content`" is returned.
|
||||
and restore flag are provided in request body, this file is restored. When
|
||||
old and new file names are provided, the file is renamed. As response
|
||||
"`204 No Content`" is returned.
|
||||
|
||||
.Response
|
||||
----
|
||||
@@ -4066,6 +4081,8 @@ path within change edit.
|
||||
|===========================
|
||||
|Field Name ||Description
|
||||
|`restore_path`|optional|Path to file to restore.
|
||||
|`old_path` |optional|Old path to file to rename.
|
||||
|`new_path` |optional|New path to file to rename.
|
||||
|===========================
|
||||
|
||||
[[change-edit-message-input]]
|
||||
|
@@ -434,6 +434,25 @@ public class ChangeEditIT extends AbstractDaemonTest {
|
||||
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME), CONTENT_OLD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renameFileRest() throws Exception {
|
||||
assertThat(modifier.createEdit(change, ps)).isEqualTo(RefUpdate.Result.NEW);
|
||||
Post.Input in = new Post.Input();
|
||||
in.oldPath = FILE_NAME;
|
||||
in.newPath = FILE_NAME3;
|
||||
assertThat(adminSession.post(urlEdit(), in).getStatusCode()).isEqualTo(
|
||||
SC_NO_CONTENT);
|
||||
Optional<ChangeEdit> edit = editUtil.byChange(change);
|
||||
assertByteArray(fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
|
||||
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME3), CONTENT_OLD);
|
||||
try {
|
||||
fileUtil.getContent(projectCache.get(edit.get().getChange().getProject()),
|
||||
ObjectId.fromString(edit.get().getRevision().get()), FILE_NAME);
|
||||
fail("ResourceNotFoundException expected");
|
||||
} catch (ResourceNotFoundException rnfe) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoreDeletedFileInPatchSetRest() throws Exception {
|
||||
Post.Input in = new Post.Input();
|
||||
|
@@ -311,6 +311,8 @@ public class ChangeEdits implements
|
||||
RestModifyView<ChangeResource, Post.Input> {
|
||||
public static class Input {
|
||||
public String restorePath;
|
||||
public String oldPath;
|
||||
public String newPath;
|
||||
}
|
||||
|
||||
private final Provider<ReviewDb> db;
|
||||
@@ -335,8 +337,13 @@ public class ChangeEdits implements
|
||||
edit = createEdit(resource.getChange());
|
||||
}
|
||||
|
||||
if (input != null && !Strings.isNullOrEmpty(input.restorePath)) {
|
||||
if (input != null) {
|
||||
if (!Strings.isNullOrEmpty(input.restorePath)) {
|
||||
editModifier.restoreFile(edit.get(), input.restorePath);
|
||||
} else if (!Strings.isNullOrEmpty(input.oldPath)
|
||||
&& !Strings.isNullOrEmpty(input.newPath)) {
|
||||
editModifier.renameFile(edit.get(), input.oldPath, input.newPath);
|
||||
}
|
||||
}
|
||||
return Response.none();
|
||||
}
|
||||
|
Reference in New Issue
Block a user