Merge "SetPrivateOp: Include non-open change's status in exception message"
This commit is contained in:
@@ -22,6 +22,7 @@ import com.google.gerrit.reviewdb.client.Change;
|
|||||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||||
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
import com.google.gerrit.server.PatchSetUtil;
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.extensions.events.PrivateStateChanged;
|
import com.google.gerrit.server.extensions.events.PrivateStateChanged;
|
||||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
@@ -83,7 +84,8 @@ public class SetPrivateOp implements BatchUpdateOp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isPrivate && !change.isNew()) {
|
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();
|
ChangeNotes notes = ctx.getNotes();
|
||||||
ps = psUtil.get(notes, change.currentPatchSetId());
|
ps = psUtil.get(notes, change.currentPatchSetId());
|
||||||
|
|||||||
@@ -90,7 +90,20 @@ public class PrivateChangeIT extends AbstractDaemonTest {
|
|||||||
assertThat(gApi.changes().id(changeId).get().isPrivate).isNull();
|
assertThat(gApi.changes().id(changeId).get().isPrivate).isNull();
|
||||||
|
|
||||||
exception.expect(BadRequestException.class);
|
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);
|
gApi.changes().id(changeId).setPrivate(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user