Search in sources :

Example 21 with ChangeMessage

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);
}
Also used : ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) Change(com.google.gerrit.reviewdb.client.Change)

Example 22 with ChangeMessage

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);
}
Also used : ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) Change(com.google.gerrit.reviewdb.client.Change)

Example 23 with ChangeMessage

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);
}
Also used : ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage)

Example 24 with ChangeMessage

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);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) TestAccount(com.google.gerrit.acceptance.TestAccount) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 25 with ChangeMessage

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());
    }
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)42 Change (com.google.gerrit.reviewdb.client.Change)31 Test (org.junit.Test)25 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)16 ObjectId (org.eclipse.jgit.lib.ObjectId)11 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)9 RevId (com.google.gerrit.reviewdb.client.RevId)8 GerritServerId (com.google.gerrit.server.config.GerritServerId)7 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)6 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)6 RequestId (com.google.gerrit.server.util.RequestId)6 Account (com.google.gerrit.reviewdb.client.Account)5 Comment (com.google.gerrit.reviewdb.client.Comment)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)4 PatchLineComment (com.google.gerrit.reviewdb.client.PatchLineComment)4 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 Table (com.google.common.collect.Table)2