Search in sources :

Example 61 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class MergedSender method format.

private String format(String type, Table<Account.Id, String, PatchSetApproval> approvals) {
    StringBuilder txt = new StringBuilder();
    if (approvals.isEmpty()) {
        return "";
    }
    txt.append(type).append(":\n");
    for (Account.Id id : approvals.rowKeySet()) {
        txt.append("  ");
        txt.append(getNameFor(id));
        txt.append(": ");
        boolean first = true;
        for (LabelType lt : labelTypes.getLabelTypes()) {
            PatchSetApproval ca = approvals.get(id, lt.getName());
            if (ca == null) {
                continue;
            }
            if (first) {
                first = false;
            } else {
                txt.append("; ");
            }
            LabelValue v = lt.getValue(ca);
            if (v != null) {
                txt.append(v.getText());
            } else {
                txt.append(lt.getName());
                txt.append('=');
                txt.append(LabelValue.formatValue(ca.value()));
            }
        }
        txt.append('\n');
    }
    txt.append('\n');
    return txt.toString();
}
Also used : Account(com.google.gerrit.entities.Account) LabelValue(com.google.gerrit.entities.LabelValue) LabelType(com.google.gerrit.entities.LabelType) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval)

Example 62 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class PRED__load_commit_labels_1 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    Term listHead = Prolog.Nil;
    ChangeData cd = StoredValues.CHANGE_DATA.get(engine);
    LabelTypes types = cd.getLabelTypes();
    for (PatchSetApproval a : cd.currentApprovals()) {
        Optional<LabelType> t = types.byLabel(a.labelId());
        if (!t.isPresent()) {
            continue;
        }
        StructureTerm labelTerm = new StructureTerm(sym_label, SymbolTerm.intern(t.get().getName()), new IntegerTerm(a.value()));
        StructureTerm userTerm = new StructureTerm(sym_user, new IntegerTerm(a.accountId().get()));
        listHead = new ListTerm(new StructureTerm(sym_commit_label, labelTerm, userTerm), listHead);
    }
    if (!a1.unify(listHead, engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : LabelTypes(com.google.gerrit.entities.LabelTypes) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) ListTerm(com.googlecode.prolog_cafe.lang.ListTerm) LabelType(com.google.gerrit.entities.LabelType) Term(com.googlecode.prolog_cafe.lang.Term) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm) ListTerm(com.googlecode.prolog_cafe.lang.ListTerm) ChangeData(com.google.gerrit.server.query.change.ChangeData) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval)

Example 63 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class EqualsLabelPredicate method match.

@Override
public boolean match(ChangeData object) {
    Change c = object.change();
    if (c == null) {
        // 
        return false;
    }
    if (Integer.valueOf(0).equals(count)) {
        // is computationally expensive.
        return false;
    }
    Optional<ProjectState> project = projectCache.get(c.getDest().project());
    if (!project.isPresent()) {
        // 
        return false;
    }
    LabelType labelType = type(project.get().getLabelTypes(), label);
    if (labelType == null) {
        // Label is not defined by this project.
        return false;
    }
    boolean hasVote = false;
    int matchingVotes = 0;
    StorageConstraint currentStorageConstraint = object.getStorageConstraint();
    object.setStorageConstraint(ChangeData.StorageConstraint.INDEX_PRIMARY_NOTEDB_SECONDARY);
    for (PatchSetApproval p : object.currentApprovals()) {
        if (labelType.matches(p)) {
            hasVote = true;
            if (match(object, p.value(), p.accountId())) {
                matchingVotes += 1;
            }
        }
    }
    object.setStorageConstraint(currentStorageConstraint);
    if (!hasVote && expVal == 0) {
        return true;
    }
    return count == null ? matchingVotes >= 1 : matchingVotes == count;
}
Also used : LabelType(com.google.gerrit.entities.LabelType) ProjectState(com.google.gerrit.server.project.ProjectState) Change(com.google.gerrit.entities.Change) StorageConstraint(com.google.gerrit.server.query.change.ChangeData.StorageConstraint) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) StorageConstraint(com.google.gerrit.server.query.change.ChangeData.StorageConstraint)

Example 64 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class StickyApprovalsIT method stickyVoteStoredCanBeRemoved.

@Test
public void stickyVoteStoredCanBeRemoved() throws Exception {
    // Code-Review will be sticky.
    String label = LabelId.CODE_REVIEW;
    try (ProjectConfigUpdate u = updateProject(project)) {
        u.getConfig().updateLabelType(label, b -> b.setCopyAnyScore(true));
        u.save();
    }
    PushOneCommit.Result r = createChange();
    // Add a new vote
    ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 2);
    gApi.changes().id(r.getChangeId()).current().review(input);
    // Make a new patchset, keeping the Code-Review +2 vote.
    amendChange(r.getChangeId());
    assertVotes(detailedChange(r.getChangeId()), admin, label, 2, null);
    gApi.changes().id(r.getChangeId()).current().review(ReviewInput.noScore());
    PatchSetApproval nonCopiedSecondPatchsetRemovedVote = Iterables.getOnlyElement(r.getChange().notes().getApprovalsWithCopied().get(r.getChange().change().currentPatchSetId()));
    assertThat(nonCopiedSecondPatchsetRemovedVote.patchSetId().get()).isEqualTo(2);
    assertThat(nonCopiedSecondPatchsetRemovedVote.accountId().get()).isEqualTo(admin.id().get());
    assertThat(nonCopiedSecondPatchsetRemovedVote.label()).isEqualTo(LabelId.CODE_REVIEW);
    // The vote got removed since the latest patch-set only has one vote and it's "0".
    assertThat(nonCopiedSecondPatchsetRemovedVote.value()).isEqualTo((short) 0);
    assertThat(nonCopiedSecondPatchsetRemovedVote.copied()).isFalse();
}
Also used : ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 65 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class StickyApprovalsIT method stickyVoteStoredOnUploadWithRealAccountAndTag.

@Test
public void stickyVoteStoredOnUploadWithRealAccountAndTag() throws Exception {
    // Give "user" permission to vote on behalf of other users.
    projectOperations.project(project).forUpdate().add(allowLabel(TestLabels.codeReview().getName()).impersonation(true).ref("refs/heads/*").group(REGISTERED_USERS).range(-1, 1)).update();
    // Code-Review will be sticky.
    String label = LabelId.CODE_REVIEW;
    try (ProjectConfigUpdate u = updateProject(project)) {
        u.getConfig().updateLabelType(label, b -> b.setCopyAnyScore(true));
        u.save();
    }
    PushOneCommit.Result r = createChange();
    // Add a new vote as user
    requestScopeOperations.setApiUser(user.id());
    ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 1);
    input.onBehalfOf = admin.email();
    input.tag = "tag";
    gApi.changes().id(r.getChangeId()).current().review(input);
    // Make a new patchset, keeping the Code-Review +1 vote.
    amendChange(r.getChangeId());
    List<PatchSetApproval> patchSetApprovals = r.getChange().notes().getApprovalsWithCopied().values().stream().sorted(comparing(a -> a.patchSetId().get())).collect(toImmutableList());
    PatchSetApproval nonCopied = patchSetApprovals.get(0);
    assertThat(nonCopied.patchSetId().get()).isEqualTo(1);
    assertThat(nonCopied.accountId().get()).isEqualTo(admin.id().get());
    assertThat(nonCopied.realAccountId().get()).isEqualTo(user.id().get());
    assertThat(nonCopied.label()).isEqualTo(LabelId.CODE_REVIEW);
    assertThat(nonCopied.value()).isEqualTo((short) 1);
    assertThat(nonCopied.tag().get()).isEqualTo("tag");
    assertThat(nonCopied.copied()).isFalse();
    PatchSetApproval copied = patchSetApprovals.get(1);
    assertThat(copied.patchSetId().get()).isEqualTo(2);
    assertThat(copied.accountId().get()).isEqualTo(admin.id().get());
    assertThat(copied.realAccountId().get()).isEqualTo(user.id().get());
    assertThat(copied.label()).isEqualTo(LabelId.CODE_REVIEW);
    assertThat(copied.value()).isEqualTo((short) 1);
    assertThat(nonCopied.tag().get()).isEqualTo("tag");
    assertThat(copied.copied()).isTrue();
}
Also used : ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)93 Test (org.junit.Test)57 Change (com.google.gerrit.entities.Change)41 LabelType (com.google.gerrit.entities.LabelType)22 Account (com.google.gerrit.entities.Account)20 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)14 Map (java.util.Map)14 ObjectId (org.eclipse.jgit.lib.ObjectId)14 LabelId (com.google.gerrit.entities.LabelId)13 PatchSet (com.google.gerrit.entities.PatchSet)12 SubmitRecord (com.google.gerrit.entities.SubmitRecord)12 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)11 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)10 SubmissionId (com.google.gerrit.entities.SubmissionId)9 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 Inject (com.google.inject.Inject)9 Instant (java.time.Instant)9 HashMap (java.util.HashMap)9 List (java.util.List)9 ChangeMessage (com.google.gerrit.entities.ChangeMessage)8