Search in sources :

Example 11 with LabelType

use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.

the class StickyApprovalsIT method setup.

@Before
public void setup() throws Exception {
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    // Overwrite "Code-Review" label that is inherited from All-Projects.
    // This way changes to the "Code Review" label don't affect other tests.
    LabelType codeReview = category("Code-Review", value(2, "Looks good to me, approved"), value(1, "Looks good to me, but someone else must approve"), value(0, "No score"), value(-1, "I would prefer that you didn't submit this"), value(-2, "Do not submit"));
    codeReview.setCopyAllScoresIfNoChange(false);
    cfg.getLabelSections().put(codeReview.getName(), codeReview);
    LabelType verified = category("Verified", value(1, "Passes"), value(0, "No score"), value(-1, "Failed"));
    verified.setCopyAllScoresIfNoChange(false);
    cfg.getLabelSections().put(verified.getName(), verified);
    AccountGroup.UUID registeredUsers = systemGroupBackend.getGroup(REGISTERED_USERS).getUUID();
    String heads = RefNames.REFS_HEADS + "*";
    Util.allow(cfg, Permission.forLabel(Util.codeReview().getName()), -2, 2, registeredUsers, heads);
    Util.allow(cfg, Permission.forLabel(Util.verified().getName()), -1, 1, registeredUsers, heads);
    saveProjectConfig(project, cfg);
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) LabelType(com.google.gerrit.common.data.LabelType) Before(org.junit.Before)

Example 12 with LabelType

use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.

the class ImpersonationIT method allowCodeReviewOnBehalfOf.

private void allowCodeReviewOnBehalfOf() throws Exception {
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    LabelType codeReviewType = Util.codeReview();
    String forCodeReviewAs = Permission.forLabelAs(codeReviewType.getName());
    String heads = "refs/heads/*";
    AccountGroup.UUID uuid = systemGroupBackend.getGroup(REGISTERED_USERS).getUUID();
    Util.allow(cfg, forCodeReviewAs, -1, 1, uuid, heads);
    saveProjectConfig(project, cfg);
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) LabelType(com.google.gerrit.common.data.LabelType)

Example 13 with LabelType

use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.

the class ChangeJson method setAllApprovals.

private void setAllApprovals(PermissionBackend.ForChange basePerm, ChangeData cd, Map<String, LabelWithStatus> labels) throws OrmException, PermissionBackendException {
    Change.Status status = cd.change().getStatus();
    checkState(status.isOpen(), "should not call setAllApprovals on %s change", status);
    // Include a user in the output for this label if either:
    //  - They are an explicit reviewer.
    //  - They ever voted on this change.
    Set<Account.Id> allUsers = new HashSet<>();
    allUsers.addAll(cd.reviewers().byState(ReviewerStateInternal.REVIEWER));
    for (PatchSetApproval psa : cd.approvals().values()) {
        allUsers.add(psa.getAccountId());
    }
    Table<Account.Id, String, PatchSetApproval> current = HashBasedTable.create(allUsers.size(), cd.getLabelTypes().getLabelTypes().size());
    for (PatchSetApproval psa : cd.currentApprovals()) {
        current.put(psa.getAccountId(), psa.getLabel(), psa);
    }
    LabelTypes labelTypes = cd.getLabelTypes();
    for (Account.Id accountId : allUsers) {
        PermissionBackend.ForChange perm = basePerm.user(userFactory.create(accountId));
        Map<String, VotingRangeInfo> pvr = getPermittedVotingRanges(permittedLabels(perm, cd));
        for (Map.Entry<String, LabelWithStatus> e : labels.entrySet()) {
            LabelType lt = labelTypes.byLabel(e.getKey());
            if (lt == null) {
                // author didn't intend for the label to show up in the table.
                continue;
            }
            Integer value;
            VotingRangeInfo permittedVotingRange = pvr.getOrDefault(lt.getName(), null);
            String tag = null;
            Timestamp date = null;
            PatchSetApproval psa = current.get(accountId, lt.getName());
            if (psa != null) {
                value = Integer.valueOf(psa.getValue());
                if (value == 0) {
                    // This may be a dummy approval that was inserted when the reviewer
                    // was added. Explicitly check whether the user can vote on this
                    // label.
                    value = perm.test(new LabelPermission(lt)) ? 0 : null;
                }
                tag = psa.getTag();
                date = psa.getGranted();
                if (psa.isPostSubmit()) {
                    log.warn("unexpected post-submit approval on open change: {}", psa);
                }
            } else {
                // Either the user cannot vote on this label, or they were added as a
                // reviewer but have not responded yet. Explicitly check whether the
                // user can vote on this label.
                value = perm.test(new LabelPermission(lt)) ? 0 : null;
            }
            addApproval(e.getValue().label(), approvalInfo(accountId, value, permittedVotingRange, tag, date));
        }
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) LabelTypes(com.google.gerrit.common.data.LabelTypes) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) VotingRangeInfo(com.google.gerrit.extensions.common.VotingRangeInfo) Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Timestamp(java.sql.Timestamp) LabelType(com.google.gerrit.common.data.LabelType) ObjectId(org.eclipse.jgit.lib.ObjectId) 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) LabelPermission(com.google.gerrit.server.permissions.LabelPermission) HashSet(java.util.HashSet)

Example 14 with LabelType

use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.

the class LabelNormalizerTest method configureProject.

private void configureProject() throws Exception {
    ProjectConfig pc = loadAllProjects();
    for (AccessSection sec : pc.getAccessSections()) {
        for (String label : pc.getLabelSections().keySet()) {
            sec.removePermission(forLabel(label));
        }
    }
    LabelType lt = category("Verified", value(1, "Verified"), value(0, "No score"), value(-1, "Fails"));
    pc.getLabelSections().put(lt.getName(), lt);
    save(pc);
}
Also used : LabelType(com.google.gerrit.common.data.LabelType) AccessSection(com.google.gerrit.common.data.AccessSection)

Example 15 with LabelType

use of com.google.gerrit.common.data.LabelType in project gerrit by GerritCodeReview.

the class ProjectConfigTest method readConfigLabelDefaultValue.

@Test
public void readConfigLabelDefaultValue() throws Exception {
    RevCommit rev = util.commit(//
    util.tree(//
    util.file("groups", util.blob(group(developers))), util.file("project.config", util.blob(//
    "" + //
    "[label \"CustomLabel\"]\n" + //
    "  value = -1 Negative\n" + //
    "  value =  0 No Score\n" + //
    "  value =  1 Positive\n"))));
    ProjectConfig cfg = read(rev);
    Map<String, LabelType> labels = cfg.getLabelSections();
    Short dv = labels.entrySet().iterator().next().getValue().getDefaultValue();
    assertThat((int) dv).isEqualTo(0);
}
Also used : LabelType(com.google.gerrit.common.data.LabelType) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

LabelType (com.google.gerrit.common.data.LabelType)38 HashMap (java.util.HashMap)10 Map (java.util.Map)10 LabelTypes (com.google.gerrit.common.data.LabelTypes)8 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)8 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)8 LabelPermission (com.google.gerrit.server.permissions.LabelPermission)8 Account (com.google.gerrit.reviewdb.client.Account)7 LabelValue (com.google.gerrit.common.data.LabelValue)6 LinkedHashMap (java.util.LinkedHashMap)6 Test (org.junit.Test)6 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)5 CurrentUser (com.google.gerrit.server.CurrentUser)5 OrmException (com.google.gwtorm.server.OrmException)5 ArrayList (java.util.ArrayList)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 DynamicMap (com.google.gerrit.extensions.registration.DynamicMap)4 Change (com.google.gerrit.reviewdb.client.Change)4 Project (com.google.gerrit.reviewdb.client.Project)4 ChangeData (com.google.gerrit.server.query.change.ChangeData)4