Merge "SetPrivateOp: Include non-open change's status in exception message"

This commit is contained in:
Edwin Kempin
2019-03-04 12:39:34 +00:00
committed by Gerrit Code Review
2 changed files with 17 additions and 2 deletions

View File

@@ -22,6 +22,7 @@ import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.extensions.events.PrivateStateChanged;
import com.google.gerrit.server.notedb.ChangeNotes;
@@ -83,7 +84,8 @@ public class SetPrivateOp implements BatchUpdateOp {
}
if (isPrivate && !change.isNew()) {
throw new BadRequestException("cannot set a non-open change to private");
throw new BadRequestException(
String.format("cannot set %s change to private", ChangeUtil.status(change)));
}
ChangeNotes notes = ctx.getNotes();
ps = psUtil.get(notes, change.currentPatchSetId());

View File

@@ -90,7 +90,20 @@ public class PrivateChangeIT extends AbstractDaemonTest {
assertThat(gApi.changes().id(changeId).get().isPrivate).isNull();
exception.expect(BadRequestException.class);
exception.expectMessage("cannot set a non-open change to private");
exception.expectMessage("cannot set merged change to private");
gApi.changes().id(changeId).setPrivate(true);
}
@Test
public void cannotSetAbandonedChangePrivate() throws Exception {
PushOneCommit.Result result = createChange();
String changeId = result.getChangeId();
gApi.changes().id(changeId).abandon();
assertThat(gApi.changes().id(changeId).get().isPrivate).isNull();
exception.expect(BadRequestException.class);
exception.expectMessage("cannot set abandoned change to private");
gApi.changes().id(changeId).setPrivate(true);
}