Return 204 No Content on DELETE /projects/*/description

When a description is deleted the key is removed from the
configuration file. Callers should expect a 204 response.

For any PUT response return the same as GET, which is ""
instead of the literal word "null" if there is no text
after the put is complete.

Change-Id: I2ba174d1129a14d862c2b26da5eb8bebc0671f63
This commit is contained in:
Shawn Pearce
2013-01-29 09:25:54 -08:00
parent 2353ff95e4
commit f3acb074dd
2 changed files with 16 additions and 8 deletions

View File

@@ -31,8 +31,8 @@ public class Module extends RestApiModule {
get(PROJECT_KIND).to(GetProject.class); get(PROJECT_KIND).to(GetProject.class);
get(PROJECT_KIND, "description").to(GetDescription.class); get(PROJECT_KIND, "description").to(GetDescription.class);
put(PROJECT_KIND, "description").to(SetDescription.class); put(PROJECT_KIND, "description").to(PutDescription.class);
delete(PROJECT_KIND, "description").to(SetDescription.class); delete(PROJECT_KIND, "description").to(PutDescription.class);
get(PROJECT_KIND, "parent").to(GetParent.class); get(PROJECT_KIND, "parent").to(GetParent.class);
put(PROJECT_KIND, "parent").to(SetParent.class); put(PROJECT_KIND, "parent").to(SetParent.class);

View File

@@ -21,19 +21,22 @@ import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.DefaultInput; import com.google.gerrit.extensions.restapi.DefaultInput;
import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestModifyView; import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.MetaDataUpdate; import com.google.gerrit.server.git.MetaDataUpdate;
import com.google.gerrit.server.git.ProjectConfig; import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.project.SetDescription.Input; import com.google.gerrit.server.project.PutDescription.Input;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.errors.RepositoryNotFoundException;
class SetDescription implements RestModifyView<ProjectResource, Input> { import java.io.IOException;
class PutDescription implements RestModifyView<ProjectResource, Input> {
static class Input { static class Input {
@DefaultInput @DefaultInput
String description; String description;
@@ -45,7 +48,7 @@ class SetDescription implements RestModifyView<ProjectResource, Input> {
private final GitRepositoryManager gitMgr; private final GitRepositoryManager gitMgr;
@Inject @Inject
SetDescription(ProjectCache cache, PutDescription(ProjectCache cache,
MetaDataUpdate.Server updateFactory, MetaDataUpdate.Server updateFactory,
GitRepositoryManager gitMgr) { GitRepositoryManager gitMgr) {
this.cache = cache; this.cache = cache;
@@ -54,11 +57,13 @@ class SetDescription implements RestModifyView<ProjectResource, Input> {
} }
@Override @Override
public String apply(ProjectResource resource, Input input) public Response<String> apply(ProjectResource resource, Input input)
throws AuthException, BadRequestException, ResourceConflictException, throws AuthException, BadRequestException, ResourceConflictException,
Exception { ResourceNotFoundException, IOException {
boolean delete = false;
if (input == null) { if (input == null) {
input = new Input(); // Delete would set description to null. input = new Input(); // Delete would set description to null.
delete = true;
} }
ProjectControl ctl = resource.getControl(); ProjectControl ctl = resource.getControl();
@@ -88,7 +93,10 @@ class SetDescription implements RestModifyView<ProjectResource, Input> {
resource.getNameKey(), resource.getNameKey(),
project.getDescription()); project.getDescription());
return project.getDescription(); if (delete) {
return Response.none();
}
return Response.ok(Strings.nullToEmpty(project.getDescription()));
} finally { } finally {
md.close(); md.close();
} }