Search in sources :

Example 6 with LabelId

use of com.google.gerrit.reviewdb.client.LabelId in project gerrit by GerritCodeReview.

the class ChangeNotesParser method parseAddApproval.

private PatchSetApproval parseAddApproval(PatchSet.Id psId, Account.Id committerId, Account.Id realAccountId, Timestamp ts, String line) throws ConfigInvalidException {
    // There are potentially 3 accounts involved here:
    //  1. The account from the commit, which is the effective IdentifiedUser
    //     that produced the update.
    //  2. The account in the label footer itself, which is used during submit
    //     to copy other users' labels to a new patch set.
    //  3. The account in the Real-user footer, indicating that the whole
    //     update operation was executed by this user on behalf of the effective
    //     user.
    Account.Id effectiveAccountId;
    String labelVoteStr;
    int s = line.indexOf(' ');
    if (s > 0) {
        // Account in the label line (2) becomes the effective ID of the
        // approval. If there is a real user (3) different from the commit user
        // (2), we actually don't store that anywhere in this case; it's more
        // important to record that the real user (3) actually initiated submit.
        labelVoteStr = line.substring(0, s);
        PersonIdent ident = RawParseUtils.parsePersonIdent(line.substring(s + 1));
        checkFooter(ident != null, FOOTER_LABEL, line);
        effectiveAccountId = noteUtil.parseIdent(ident, id);
    } else {
        labelVoteStr = line;
        effectiveAccountId = committerId;
    }
    LabelVote l;
    try {
        l = LabelVote.parseWithEquals(labelVoteStr);
    } catch (IllegalArgumentException e) {
        ConfigInvalidException pe = parseException("invalid %s: %s", FOOTER_LABEL, line);
        pe.initCause(e);
        throw pe;
    }
    PatchSetApproval psa = new PatchSetApproval(new PatchSetApproval.Key(psId, effectiveAccountId, new LabelId(l.label())), l.value(), ts);
    psa.setTag(tag);
    if (!Objects.equals(realAccountId, committerId)) {
        psa.setRealAccountId(realAccountId);
    }
    ApprovalKey k = ApprovalKey.create(psId, effectiveAccountId, l.label());
    if (!approvals.containsKey(k)) {
        approvals.put(k, psa);
    }
    return psa;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) LabelVote(com.google.gerrit.server.util.LabelVote) LabelId(com.google.gerrit.reviewdb.client.LabelId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Example 7 with LabelId

use of com.google.gerrit.reviewdb.client.LabelId in project gerrit by GerritCodeReview.

the class ChangeBundleTest method diffPatchSetApprovalsIgnoresPostSubmitBitOnZeroVote.

@Test
public void diffPatchSetApprovalsIgnoresPostSubmitBitOnZeroVote() throws Exception {
    Change c = TestChanges.newChange(project, accountId);
    c.setStatus(Change.Status.MERGED);
    PatchSetApproval a1 = new PatchSetApproval(new PatchSetApproval.Key(c.currentPatchSetId(), accountId, new LabelId("Code-Review")), (short) 0, TimeUtil.nowTs());
    a1.setPostSubmit(false);
    PatchSetApproval a2 = clone(a1);
    a2.setPostSubmit(true);
    // Both are ReviewDb, exact match is required.
    ChangeBundle b1 = new ChangeBundle(c, messages(), latest(c), approvals(a1), comments(), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c, messages(), latest(c), approvals(a2), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "postSubmit differs for PatchSetApproval.Key " + c.getId() + "%2C1,100,Code-Review:" + " {false} != {true}");
    // One NoteDb, postSubmit is ignored.
    b1 = new ChangeBundle(c, messages(), latest(c), approvals(a1), comments(), reviewers(), REVIEW_DB);
    b2 = new ChangeBundle(c, messages(), latest(c), approvals(a2), comments(), reviewers(), NOTE_DB);
    assertNoDiffs(b1, b2);
    assertNoDiffs(b2, b1);
    // postSubmit is not ignored if vote isn't 0.
    a1.setValue((short) 1);
    a2.setValue((short) 1);
    assertDiffs(b1, b2, "postSubmit differs for PatchSetApproval.Key " + c.getId() + "%2C1,100,Code-Review:" + " {false} != {true}");
    assertDiffs(b2, b1, "postSubmit differs for PatchSetApproval.Key " + c.getId() + "%2C1,100,Code-Review:" + " {true} != {false}");
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) LabelId(com.google.gerrit.reviewdb.client.LabelId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Example 8 with LabelId

use of com.google.gerrit.reviewdb.client.LabelId in project gerrit by GerritCodeReview.

the class ChangeBundleTest method diffPatchSetsGreaterThanCurrent.

@Test
public void diffPatchSetsGreaterThanCurrent() throws Exception {
    Change c = TestChanges.newChange(project, accountId);
    PatchSet ps1 = new PatchSet(new PatchSet.Id(c.getId(), 1));
    ps1.setRevision(new RevId("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
    ps1.setUploader(accountId);
    ps1.setCreatedOn(TimeUtil.nowTs());
    PatchSet ps2 = new PatchSet(new PatchSet.Id(c.getId(), 2));
    ps2.setRevision(new RevId("badc0feebadc0feebadc0feebadc0feebadc0fee"));
    ps2.setUploader(accountId);
    ps2.setCreatedOn(TimeUtil.nowTs());
    assertThat(ps2.getId().get()).isGreaterThan(c.currentPatchSetId().get());
    ChangeMessage cm1 = new ChangeMessage(new ChangeMessage.Key(c.getId(), "uuid1"), accountId, TimeUtil.nowTs(), c.currentPatchSetId());
    ChangeMessage cm2 = new ChangeMessage(new ChangeMessage.Key(c.getId(), "uuid2"), accountId, TimeUtil.nowTs(), c.currentPatchSetId());
    PatchSetApproval a1 = new PatchSetApproval(new PatchSetApproval.Key(ps1.getId(), accountId, new LabelId("Code-Review")), (short) 1, TimeUtil.nowTs());
    PatchSetApproval a2 = new PatchSetApproval(new PatchSetApproval.Key(ps2.getId(), accountId, new LabelId("Code-Review")), (short) 1, TimeUtil.nowTs());
    // Both ReviewDb.
    ChangeBundle b1 = new ChangeBundle(c, messages(cm1), patchSets(ps1), approvals(a1), comments(), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c, messages(cm1, cm2), patchSets(ps1, ps2), approvals(a1, a2), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "ChangeMessage.Key sets differ: [] only in A; [" + cm2.getKey() + "] only in B", "PatchSet.Id sets differ: [] only in A; [" + ps2.getId() + "] only in B", "PatchSetApproval.Key sets differ: [] only in A; [" + a2.getKey() + "] only in B");
    // One NoteDb.
    b1 = new ChangeBundle(c, messages(cm1), patchSets(ps1), approvals(a1), comments(), reviewers(), NOTE_DB);
    b2 = new ChangeBundle(c, messages(cm1, cm2), patchSets(ps1, ps2), approvals(a1, a2), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "ChangeMessages differ for Change.Id " + c.getId() + "\nOnly in B:\n  " + cm2, "PatchSet.Id sets differ: [] only in A; [" + ps2.getId() + "] only in B", "PatchSetApproval.Key sets differ: [] only in A; [" + a2.getKey() + "] only in B");
    // Both NoteDb.
    b1 = new ChangeBundle(c, messages(cm1), patchSets(ps1), approvals(a1), comments(), reviewers(), NOTE_DB);
    b2 = new ChangeBundle(c, messages(cm1, cm2), patchSets(ps1, ps2), approvals(a1, a2), comments(), reviewers(), NOTE_DB);
    assertDiffs(b1, b2, "ChangeMessages differ for Change.Id " + c.getId() + "\nOnly in B:\n  " + cm2, "PatchSet.Id sets differ: [] only in A; [" + ps2.getId() + "] only in B", "PatchSetApproval.Key sets differ: [] only in A; [" + a2.getKey() + "] only in B");
}
Also used : ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) LabelId(com.google.gerrit.reviewdb.client.LabelId) RevId(com.google.gerrit.reviewdb.client.RevId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Example 9 with LabelId

use of com.google.gerrit.reviewdb.client.LabelId in project gerrit by GerritCodeReview.

the class ChangeBundleTest method diffPatchSetApprovalsAllowsTruncatedTimestampInNoteDb.

@Test
public void diffPatchSetApprovalsAllowsTruncatedTimestampInNoteDb() throws Exception {
    Change c = TestChanges.newChange(project, accountId);
    PatchSetApproval a1 = new PatchSetApproval(new PatchSetApproval.Key(c.currentPatchSetId(), accountId, new LabelId("Code-Review")), (short) 1, c.getCreatedOn());
    PatchSetApproval a2 = clone(a1);
    a2.setGranted(new Timestamp(new DateTime(1900, 1, 1, 0, 0, 0, DateTimeZone.forTimeZone(TimeZone.getDefault())).getMillis()));
    // Both are ReviewDb, exact match is required.
    ChangeBundle b1 = new ChangeBundle(c, messages(), latest(c), approvals(a1), comments(), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c, messages(), latest(c), approvals(a2), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "granted differs for PatchSetApproval.Key " + c.getId() + "%2C1,100,Code-Review:" + " {2009-09-30 17:00:00.0} != {1900-01-01 00:00:00.0}");
    // Truncating NoteDb timestamp is allowed.
    b1 = new ChangeBundle(c, messages(), latest(c), approvals(a1), comments(), reviewers(), NOTE_DB);
    b2 = new ChangeBundle(c, messages(), latest(c), approvals(a2), comments(), reviewers(), REVIEW_DB);
    assertNoDiffs(b1, b2);
    assertNoDiffs(b2, b1);
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) LabelId(com.google.gerrit.reviewdb.client.LabelId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Timestamp(java.sql.Timestamp) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 10 with LabelId

use of com.google.gerrit.reviewdb.client.LabelId in project gerrit by GerritCodeReview.

the class ChangeBundleTest method diffChangesIgnoresChangeTimestampIfAnyOtherEntitiesExist.

@Test
public void diffChangesIgnoresChangeTimestampIfAnyOtherEntitiesExist() {
    Change c1 = TestChanges.newChange(new Project.NameKey("project"), new Account.Id(100));
    PatchSet ps = new PatchSet(c1.currentPatchSetId());
    ps.setRevision(new RevId("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
    ps.setUploader(accountId);
    ps.setCreatedOn(TimeUtil.nowTs());
    PatchSetApproval a = new PatchSetApproval(new PatchSetApproval.Key(c1.currentPatchSetId(), accountId, new LabelId("Code-Review")), (short) 1, TimeUtil.nowTs());
    c1.setLastUpdatedOn(a.getGranted());
    Change c2 = clone(c1);
    c2.setLastUpdatedOn(TimeUtil.nowTs());
    // ReviewDb has later lastUpdatedOn timestamp than NoteDb, allowed since
    // NoteDb matches the latest timestamp of a non-Change entity.
    ChangeBundle b1 = new ChangeBundle(c2, messages(), patchSets(ps), approvals(a), comments(), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c1, messages(), patchSets(ps), approvals(a), comments(), reviewers(), NOTE_DB);
    assertThat(b1.getChange().getLastUpdatedOn()).isGreaterThan(b2.getChange().getLastUpdatedOn());
    assertNoDiffs(b1, b2);
    // Timestamps must actually match if Change is the only entity.
    b1 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
    b2 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
    assertDiffs(b1, b2, "effective last updated time differs for Change.Id " + c1.getId() + " in NoteDb vs. ReviewDb:" + " {2009-09-30 17:00:12.0} != {2009-09-30 17:00:18.0}");
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Account(com.google.gerrit.reviewdb.client.Account) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) LabelId(com.google.gerrit.reviewdb.client.LabelId) RevId(com.google.gerrit.reviewdb.client.RevId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Aggregations

LabelId (com.google.gerrit.reviewdb.client.LabelId)12 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)12 Test (org.junit.Test)9 Change (com.google.gerrit.reviewdb.client.Change)8 Account (com.google.gerrit.reviewdb.client.Account)5 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)3 RevId (com.google.gerrit.reviewdb.client.RevId)3 Project (com.google.gerrit.reviewdb.client.Project)2 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)2 PersonIdent (org.eclipse.jgit.lib.PersonIdent)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 LabelType (com.google.gerrit.common.data.LabelType)1 AddReviewerInput (com.google.gerrit.extensions.api.changes.AddReviewerInput)1 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)1 LabelVote (com.google.gerrit.server.util.LabelVote)1 Timestamp (java.sql.Timestamp)1 DateTime (org.joda.time.DateTime)1