Search in sources :

Example 51 with PatchSetApproval

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

the class ChangeBundle method getLatestTimestamp.

private Timestamp getLatestTimestamp() {
    Ordering<Timestamp> o = Ordering.natural().nullsFirst();
    Timestamp ts = null;
    for (ChangeMessage cm : filterChangeMessages()) {
        ts = o.max(ts, cm.getWrittenOn());
    }
    for (PatchSet ps : getPatchSets()) {
        ts = o.max(ts, ps.getCreatedOn());
    }
    for (PatchSetApproval psa : filterPatchSetApprovals().values()) {
        ts = o.max(ts, psa.getGranted());
    }
    for (PatchLineComment plc : filterPatchLineComments().values()) {
        // Ignore draft comments, as they do not show up in the change meta graph.
        if (plc.getStatus() != PatchLineComment.Status.DRAFT) {
            ts = o.max(ts, plc.getWrittenOn());
        }
    }
    return firstNonNull(ts, change.getLastUpdatedOn());
}
Also used : PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Timestamp(java.sql.Timestamp) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Example 52 with PatchSetApproval

use of com.google.gerrit.reviewdb.client.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;
    try {
        ChangeData cd = StoredValues.CHANGE_DATA.get(engine);
        LabelTypes types = cd.getLabelTypes();
        for (PatchSetApproval a : cd.currentApprovals()) {
            LabelType t = types.byLabel(a.getLabelId());
            if (t == null) {
                continue;
            }
            StructureTerm labelTerm = new StructureTerm(sym_label, SymbolTerm.intern(t.getName()), new IntegerTerm(a.getValue()));
            StructureTerm userTerm = new StructureTerm(sym_user, new IntegerTerm(a.getAccountId().get()));
            listHead = new ListTerm(new StructureTerm(sym_commit_label, labelTerm, userTerm), listHead);
        }
    } catch (OrmException err) {
        throw new JavaException(this, 1, err);
    }
    if (!a1.unify(listHead, engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : LabelTypes(com.google.gerrit.common.data.LabelTypes) IntegerTerm(com.googlecode.prolog_cafe.lang.IntegerTerm) JavaException(com.googlecode.prolog_cafe.exceptions.JavaException) StructureTerm(com.googlecode.prolog_cafe.lang.StructureTerm) ListTerm(com.googlecode.prolog_cafe.lang.ListTerm) OrmException(com.google.gwtorm.server.OrmException) LabelType(com.google.gerrit.common.data.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.reviewdb.client.PatchSetApproval)

Example 53 with PatchSetApproval

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

the class ChangeJson method labelsForOpenChange.

private Map<String, LabelWithStatus> labelsForOpenChange(PermissionBackend.ForChange perm, ChangeData cd, LabelTypes labelTypes, boolean standard, boolean detailed) throws OrmException, PermissionBackendException {
    Map<String, LabelWithStatus> labels = initLabels(cd, labelTypes, standard);
    if (detailed) {
        setAllApprovals(perm, cd, labels);
    }
    for (Map.Entry<String, LabelWithStatus> e : labels.entrySet()) {
        LabelType type = labelTypes.byLabel(e.getKey());
        if (type == null) {
            continue;
        }
        if (standard) {
            for (PatchSetApproval psa : cd.currentApprovals()) {
                if (type.matches(psa)) {
                    short val = psa.getValue();
                    Account.Id accountId = psa.getAccountId();
                    setLabelScores(type, e.getValue(), val, accountId);
                }
            }
        }
        if (detailed) {
            setLabelValues(type, e.getValue());
        }
    }
    return labels;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) LabelType(com.google.gerrit.common.data.LabelType) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Example 54 with PatchSetApproval

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

the class SubmitStrategyOp method zero.

private static Iterable<PatchSetApproval> zero(Iterable<PatchSetApproval> approvals) {
    return Iterables.transform(approvals, a -> {
        PatchSetApproval copy = new PatchSetApproval(a.getPatchSetId(), a);
        copy.setValue((short) 0);
        return copy;
    });
}
Also used : PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Example 55 with PatchSetApproval

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

the class LabelNormalizerTest method normalizeByType.

@Test
public void normalizeByType() throws Exception {
    ProjectConfig pc = loadAllProjects();
    allow(pc, forLabel("Code-Review"), -5, 5, REGISTERED_USERS, "refs/heads/*");
    allow(pc, forLabel("Verified"), -5, 5, REGISTERED_USERS, "refs/heads/*");
    save(pc);
    PatchSetApproval cr = psa(userId, "Code-Review", 5);
    PatchSetApproval v = psa(userId, "Verified", 5);
    assertEquals(Result.create(list(), list(copy(cr, 2), copy(v, 1)), list()), norm.normalize(change, list(cr, v)));
}
Also used : PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Aggregations

PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)71 Change (com.google.gerrit.reviewdb.client.Change)37 Test (org.junit.Test)32 Account (com.google.gerrit.reviewdb.client.Account)17 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)17 LabelType (com.google.gerrit.common.data.LabelType)14 LabelId (com.google.gerrit.reviewdb.client.LabelId)13 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)10 ChangeData (com.google.gerrit.server.query.change.ChangeData)10 ObjectId (org.eclipse.jgit.lib.ObjectId)10 RevId (com.google.gerrit.reviewdb.client.RevId)8 Timestamp (java.sql.Timestamp)8 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)7 HashMap (java.util.HashMap)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 LabelTypes (com.google.gerrit.common.data.LabelTypes)6 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 RequestId (com.google.gerrit.server.util.RequestId)5