ChangeEditApi: Introduce modifyFile variant with FileContentInput

Add a new variant of modifyFile that takes a FileContentInput, and
change the existing one to a default implementation that uses it.

This will make it easier to extend the API in future by adding new
fields in the input.

In future the original modifyFile method can be deprecated. It is
not done in this commit because there are still a lot of places
where it's used.

Change-Id: I51f80596353a642ddd844a955a069e9328c373b6
This commit is contained in:
David Pursehouse
2019-12-17 13:35:32 +09:00
parent 11ad01a1b0
commit f2134ed53d
2 changed files with 18 additions and 6 deletions

View File

@@ -150,7 +150,22 @@ public interface ChangeEditApi {
* @param newContent the desired content of the file
* @throws RestApiException if the content of the file couldn't be modified
*/
void modifyFile(String filePath, RawInput newContent) throws RestApiException;
default void modifyFile(String filePath, RawInput newContent) throws RestApiException {
FileContentInput input = new FileContentInput();
input.content = newContent;
modifyFile(filePath, input);
}
/**
* Modify the contents of the specified file of the change edit. If no content is provided, the
* content of the file is erased but the file isn't deleted. If the change edit doesn't exist, it
* will be created based on the current patch set of the change.
*
* @param filePath the path of the file which should be modified
* @param input the desired content of the file
* @throws RestApiException if the content of the file couldn't be modified
*/
void modifyFile(String filePath, FileContentInput input) throws RestApiException;
/**
* Deletes the specified file from the change edit. If the change edit doesn't exist, it will be
@@ -235,7 +250,7 @@ public interface ChangeEditApi {
}
@Override
public void modifyFile(String filePath, RawInput newContent) throws RestApiException {
public void modifyFile(String filePath, FileContentInput input) throws RestApiException {
throw new NotImplementedException();
}

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.extensions.common.Input;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BinaryResult;
import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.RawInput;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException;
@@ -201,10 +200,8 @@ public class ChangeEditApiImpl implements ChangeEditApi {
}
@Override
public void modifyFile(String filePath, RawInput newContent) throws RestApiException {
public void modifyFile(String filePath, FileContentInput input) throws RestApiException {
try {
FileContentInput input = new FileContentInput();
input.content = newContent;
changeEditsPut.apply(changeResource, filePath, input);
} catch (Exception e) {
throw asRestApiException("Cannot modify file of change edit", e);