Search in sources :

Example 16 with LabelType

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

the class ProjectConfigTest method readConfigLabelDefaultValueInRange.

@Test
public void readConfigLabelDefaultValueInRange() 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" + //
    "  defaultValue = -1\n"))));
    ProjectConfig cfg = read(rev);
    Map<String, LabelType> labels = cfg.getLabelSections();
    Short dv = labels.entrySet().iterator().next().getValue().getDefaultValue();
    assertThat((int) dv).isEqualTo(-1);
}
Also used : LabelType(com.google.gerrit.common.data.LabelType) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 17 with LabelType

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

the class ApprovalsUtil method addApprovalsForNewPatchSet.

/**
   * Adds approvals to ChangeUpdate for a new patch set, and writes to ReviewDb.
   *
   * @param db review database.
   * @param update change update.
   * @param labelTypes label types for the containing project.
   * @param ps patch set being approved.
   * @param changeCtl change control for user adding approvals.
   * @param approvals approvals to add.
   * @throws RestApiException
   * @throws OrmException
   */
public Iterable<PatchSetApproval> addApprovalsForNewPatchSet(ReviewDb db, ChangeUpdate update, LabelTypes labelTypes, PatchSet ps, ChangeControl changeCtl, Map<String, Short> approvals) throws RestApiException, OrmException {
    Account.Id accountId = changeCtl.getUser().getAccountId();
    checkArgument(accountId.equals(ps.getUploader()), "expected user %s to match patch set uploader %s", accountId, ps.getUploader());
    if (approvals.isEmpty()) {
        return ImmutableList.of();
    }
    checkApprovals(approvals, changeCtl);
    List<PatchSetApproval> cells = new ArrayList<>(approvals.size());
    Date ts = update.getWhen();
    for (Map.Entry<String, Short> vote : approvals.entrySet()) {
        LabelType lt = labelTypes.byLabel(vote.getKey());
        cells.add(newApproval(ps.getId(), changeCtl.getUser(), lt.getLabelId(), vote.getValue(), ts));
    }
    for (PatchSetApproval psa : cells) {
        update.putApproval(psa.getLabel(), psa.getValue());
    }
    db.patchSetApprovals().insert(cells);
    return cells;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) LabelType(com.google.gerrit.common.data.LabelType) ArrayList(java.util.ArrayList) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Map(java.util.Map) Date(java.util.Date)

Example 18 with LabelType

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

the class AllProjectsCreator method initAllProjects.

private void initAllProjects(Repository git) throws IOException, ConfigInvalidException {
    BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
    try (MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allProjectsName, git, bru)) {
        md.getCommitBuilder().setAuthor(serverUser);
        md.getCommitBuilder().setCommitter(serverUser);
        md.setMessage(MoreObjects.firstNonNull(Strings.emptyToNull(message), "Initialized Gerrit Code Review " + Version.getVersion()));
        ProjectConfig config = ProjectConfig.read(md);
        Project p = config.getProject();
        p.setDescription("Access inherited by all other projects.");
        p.setRequireChangeID(InheritableBoolean.TRUE);
        p.setUseContentMerge(InheritableBoolean.TRUE);
        p.setUseContributorAgreements(InheritableBoolean.FALSE);
        p.setUseSignedOffBy(InheritableBoolean.FALSE);
        p.setEnableSignedPush(InheritableBoolean.FALSE);
        AccessSection cap = config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true);
        AccessSection all = config.getAccessSection(AccessSection.ALL, true);
        AccessSection heads = config.getAccessSection(AccessSection.HEADS, true);
        AccessSection tags = config.getAccessSection("refs/tags/*", true);
        AccessSection meta = config.getAccessSection(RefNames.REFS_CONFIG, true);
        AccessSection refsFor = config.getAccessSection("refs/for/*", true);
        AccessSection magic = config.getAccessSection("refs/for/" + AccessSection.ALL, true);
        grant(config, cap, GlobalCapability.ADMINISTRATE_SERVER, admin);
        grant(config, all, Permission.READ, admin, anonymous);
        grant(config, refsFor, Permission.ADD_PATCH_SET, registered);
        if (batch != null) {
            Permission priority = cap.getPermission(GlobalCapability.PRIORITY, true);
            PermissionRule r = rule(config, batch);
            r.setAction(Action.BATCH);
            priority.add(r);
            Permission stream = cap.getPermission(GlobalCapability.STREAM_EVENTS, true);
            stream.add(rule(config, batch));
        }
        LabelType cr = initCodeReviewLabel(config);
        grant(config, heads, cr, -1, 1, registered);
        grant(config, heads, cr, -2, 2, admin, owners);
        grant(config, heads, Permission.CREATE, admin, owners);
        grant(config, heads, Permission.PUSH, admin, owners);
        grant(config, heads, Permission.SUBMIT, admin, owners);
        grant(config, heads, Permission.FORGE_AUTHOR, registered);
        grant(config, heads, Permission.FORGE_COMMITTER, admin, owners);
        grant(config, heads, Permission.EDIT_TOPIC_NAME, true, admin, owners);
        grant(config, tags, Permission.CREATE, admin, owners);
        grant(config, tags, Permission.CREATE_TAG, admin, owners);
        grant(config, tags, Permission.CREATE_SIGNED_TAG, admin, owners);
        grant(config, magic, Permission.PUSH, registered);
        grant(config, magic, Permission.PUSH_MERGE, registered);
        meta.getPermission(Permission.READ, true).setExclusiveGroup(true);
        grant(config, meta, Permission.READ, admin, owners);
        grant(config, meta, cr, -2, 2, admin, owners);
        grant(config, meta, Permission.CREATE, admin, owners);
        grant(config, meta, Permission.PUSH, admin, owners);
        grant(config, meta, Permission.SUBMIT, admin, owners);
        config.commitToNewRef(md, RefNames.REFS_CONFIG);
        initSequences(git, bru);
        execute(git, bru);
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Project(com.google.gerrit.reviewdb.client.Project) PermissionRule(com.google.gerrit.common.data.PermissionRule) LabelType(com.google.gerrit.common.data.LabelType) Permission(com.google.gerrit.common.data.Permission) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) AccessSection(com.google.gerrit.common.data.AccessSection) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 19 with LabelType

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

the class Util method patchSetLock.

public static final LabelType patchSetLock() {
    LabelType label = category("Patch-Set-Lock", value(1, "Patch Set Locked"), value(0, "Patch Set Unlocked"));
    label.setFunctionName("PatchSetLock");
    return label;
}
Also used : LabelType(com.google.gerrit.common.data.LabelType)

Example 20 with LabelType

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

the class ChangeIT method checkLabelsForOpenChange.

@Test
public void checkLabelsForOpenChange() throws Exception {
    PushOneCommit.Result r = createChange();
    ChangeInfo change = gApi.changes().id(r.getChangeId()).get();
    assertThat(change.status).isEqualTo(ChangeStatus.NEW);
    assertThat(change.labels.keySet()).containsExactly("Code-Review");
    assertThat(change.permittedLabels.keySet()).containsExactly("Code-Review");
    // add new label and assert that it's returned for existing changes
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    LabelType verified = Util.verified();
    cfg.getLabelSections().put(verified.getName(), verified);
    AccountGroup.UUID registeredUsers = systemGroupBackend.getGroup(REGISTERED_USERS).getUUID();
    String heads = RefNames.REFS_HEADS + "*";
    Util.allow(cfg, Permission.forLabel(verified.getName()), -1, 1, registeredUsers, heads);
    saveProjectConfig(project, cfg);
    change = gApi.changes().id(r.getChangeId()).get();
    assertThat(change.labels.keySet()).containsExactly("Code-Review", "Verified");
    assertThat(change.permittedLabels.keySet()).containsExactly("Code-Review", "Verified");
    assertPermitted(change, "Code-Review", -2, -1, 0, 1, 2);
    assertPermitted(change, "Verified", -1, 0, 1);
    // add an approval on the new label
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(new ReviewInput().label(verified.getName(), verified.getMax().getValue()));
    // remove label and assert that it's no longer returned for existing
    // changes, even if there is an approval for it
    cfg.getLabelSections().remove(verified.getName());
    Util.remove(cfg, Permission.forLabel(verified.getName()), registeredUsers, heads);
    saveProjectConfig(project, cfg);
    change = gApi.changes().id(r.getChangeId()).get();
    assertThat(change.labels.keySet()).containsExactly("Code-Review");
    assertThat(change.permittedLabels.keySet()).containsExactly("Code-Review");
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) LabelType(com.google.gerrit.common.data.LabelType) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) 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