Search in sources :

Example 11 with LabelId

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

the class ChangeBundleTest method diffPatchSetApprovals.

@Test
public void diffPatchSetApprovals() throws Exception {
    Change c = TestChanges.newChange(project, accountId);
    PatchSetApproval a1 = new PatchSetApproval(new PatchSetApproval.Key(c.currentPatchSetId(), accountId, new LabelId("Code-Review")), (short) 1, TimeUtil.nowTs());
    PatchSetApproval a2 = clone(a1);
    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);
    assertNoDiffs(b1, b2);
    a2.setValue((short) -1);
    assertDiffs(b1, b2, "value differs for PatchSetApproval.Key " + c.getId() + "%2C1,100,Code-Review: {1} != {-1}");
}
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 12 with LabelId

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

the class ApprovalsUtil method addReviewers.

private List<PatchSetApproval> addReviewers(ReviewDb db, ChangeUpdate update, LabelTypes labelTypes, Change change, PatchSet.Id psId, Account.Id authorId, Account.Id committerId, Iterable<Account.Id> wantReviewers, Collection<Account.Id> existingReviewers) throws OrmException {
    List<LabelType> allTypes = labelTypes.getLabelTypes();
    if (allTypes.isEmpty()) {
        return ImmutableList.of();
    }
    Set<Account.Id> need = Sets.newLinkedHashSet(wantReviewers);
    if (authorId != null && canSee(db, update.getNotes(), authorId)) {
        need.add(authorId);
    }
    if (committerId != null && canSee(db, update.getNotes(), committerId)) {
        need.add(committerId);
    }
    need.remove(change.getOwner());
    need.removeAll(existingReviewers);
    if (need.isEmpty()) {
        return ImmutableList.of();
    }
    List<PatchSetApproval> cells = Lists.newArrayListWithCapacity(need.size());
    LabelId labelId = Iterables.getLast(allTypes).getLabelId();
    for (Account.Id account : need) {
        cells.add(new PatchSetApproval(new PatchSetApproval.Key(psId, account, labelId), (short) 0, update.getWhen()));
        update.putReviewer(account, REVIEWER);
    }
    db.patchSetApprovals().upsert(cells);
    return Collections.unmodifiableList(cells);
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) LabelType(com.google.gerrit.common.data.LabelType) LabelId(com.google.gerrit.reviewdb.client.LabelId) LabelId(com.google.gerrit.reviewdb.client.LabelId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

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