use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class WorkInProgressOp method addMessage.
private void addMessage(ChangeContext ctx, ChangeUpdate update) throws OrmException {
Change c = ctx.getChange();
StringBuilder buf = new StringBuilder(c.isWorkInProgress() ? "Set Work In Progress" : "Set Ready For Review");
String m = Strings.nullToEmpty(in == null ? null : in.message).trim();
if (!m.isEmpty()) {
buf.append("\n\n");
buf.append(m);
}
ChangeMessage cmsg = ChangeMessagesUtil.newMessage(ctx, buf.toString(), c.isWorkInProgress() ? ChangeMessagesUtil.TAG_SET_WIP : ChangeMessagesUtil.TAG_SET_READY);
cmUtil.addChangeMessage(ctx.getDb(), update, cmsg);
}
use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class SetPrivateOp method addMessage.
private void addMessage(ChangeContext ctx, ChangeUpdate update) throws OrmException {
Change c = ctx.getChange();
StringBuilder buf = new StringBuilder(c.isPrivate() ? "Set private" : "Unset private");
String m = Strings.nullToEmpty(input == null ? null : input.message).trim();
if (!m.isEmpty()) {
buf.append("\n\n");
buf.append(m);
}
ChangeMessage cmsg = ChangeMessagesUtil.newMessage(ctx, buf.toString(), c.isPrivate() ? ChangeMessagesUtil.TAG_SET_PRIVATE : ChangeMessagesUtil.TAG_UNSET_PRIVATE);
cmUtil.addChangeMessage(ctx.getDb(), update, cmsg);
}
use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class SetHashtagsOp method addMessage.
private void addMessage(ChangeContext ctx, ChangeUpdate update) throws OrmException {
StringBuilder msg = new StringBuilder();
appendHashtagMessage(msg, "added", toAdd);
appendHashtagMessage(msg, "removed", toRemove);
ChangeMessage cmsg = ChangeMessagesUtil.newMessage(ctx, msg.toString(), ChangeMessagesUtil.TAG_SET_HASHTAGS);
cmUtil.addChangeMessage(ctx.getDb(), update, cmsg);
}
use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class ImpersonationIT method runAsWithOnBehalfOf.
@Test
public void runAsWithOnBehalfOf() throws Exception {
// - Has the same restrictions as on_behalf_of (e.g. requires labels).
// - Takes the effective user from on_behalf_of (user).
// - Takes the real user from the real caller, not the intermediate
// X-Gerrit-RunAs user (user2).
allowRunAs();
allowCodeReviewOnBehalfOf();
TestAccount user2 = accounts.user2();
PushOneCommit.Result r = createChange();
ReviewInput in = new ReviewInput();
in.onBehalfOf = user.id.toString();
in.message = "Message on behalf of";
String endpoint = "/changes/" + r.getChangeId() + "/revisions/current/review";
RestResponse res = adminRestSession.postWithHeader(endpoint, in, runAsHeader(user2.id));
res.assertForbidden();
assertThat(res.getEntityContent()).isEqualTo("label required to post review on behalf of \"" + in.onBehalfOf + '"');
in.label("Code-Review", 1);
adminRestSession.postWithHeader(endpoint, in, runAsHeader(user2.id)).assertOK();
PatchSetApproval psa = Iterables.getOnlyElement(r.getChange().approvals().values());
assertThat(psa.getPatchSetId().get()).isEqualTo(1);
assertThat(psa.getLabel()).isEqualTo("Code-Review");
assertThat(psa.getAccountId()).isEqualTo(user.id);
assertThat(psa.getValue()).isEqualTo(1);
// not user2
assertThat(psa.getRealAccountId()).isEqualTo(admin.id);
ChangeData cd = r.getChange();
ChangeMessage m = Iterables.getLast(cmUtil.byChange(db, cd.notes()));
assertThat(m.getMessage()).endsWith(in.message);
assertThat(m.getAuthor()).isEqualTo(user.id);
// not user2
assertThat(m.getRealAuthor()).isEqualTo(admin.id);
}
use of com.google.gerrit.reviewdb.client.ChangeMessage in project gerrit by GerritCodeReview.
the class DeleteDraftPatchSetIT method deleteDraftPS1.
@Test
public void deleteDraftPS1() throws Exception {
String changeId = createDraftChangeWith2PS();
ReviewInput rin = new ReviewInput();
rin.message = "Change message";
CommentInput cin = new CommentInput();
cin.line = 1;
cin.patchSet = 1;
cin.path = PushOneCommit.FILE_NAME;
cin.side = Side.REVISION;
cin.message = "Inline comment";
rin.comments = new HashMap<>();
rin.comments.put(cin.path, ImmutableList.of(cin));
gApi.changes().id(changeId).revision(1).review(rin);
ChangeData cd = getChange(changeId);
PatchSet.Id delPsId = new PatchSet.Id(cd.getId(), 1);
PatchSet ps = cd.patchSet(delPsId);
deletePatchSet(changeId, ps);
cd = getChange(changeId);
assertThat(cd.patchSets()).hasSize(1);
assertThat(Iterables.getOnlyElement(cd.patchSets()).getId().get()).isEqualTo(2);
// Other entities based on deleted patch sets are also deleted.
for (ChangeMessage m : cd.messages()) {
assertThat(m.getPatchSetId()).named(m.toString()).isNotEqualTo(delPsId);
}
for (Comment c : cd.publishedComments()) {
assertThat(c.key.patchSetId).named(c.toString()).isNotEqualTo(delPsId.get());
}
}
Aggregations