Search in sources :

Example 16 with ProjectState

use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.

the class ProjectLevelConfigIT method withMergedInheritance.

@Test
public void withMergedInheritance() throws Exception {
    String configName = "test.config";
    Config parentCfg = new Config();
    parentCfg.setString("s1", null, "k1", "parentValue1");
    parentCfg.setString("s1", null, "k2", "parentValue2");
    parentCfg.setString("s2", "ss", "k3", "parentValue3");
    parentCfg.setString("s2", "ss", "k4", "parentValue4");
    pushFactory.create(admin.newIdent(), testRepo, "Create Project Level Config", configName, parentCfg.toText()).to(RefNames.REFS_CONFIG).assertOkStatus();
    Project.NameKey childProject = projectOperations.newProject().parent(project).create();
    TestRepository<?> childTestRepo = cloneProject(childProject);
    fetch(childTestRepo, RefNames.REFS_CONFIG + ":refs/heads/config");
    childTestRepo.reset("refs/heads/config");
    Config cfg = new Config();
    cfg.setString("s1", null, "k1", "parentValue1");
    cfg.setString("s1", null, "k2", "parentValue2");
    cfg.setString("s2", "ss", "k3", "parentValue3");
    cfg.setString("s2", "ss", "k4", "parentValue4");
    cfg.setString("s1", null, "k1", "childValue1");
    cfg.setString("s2", "ss", "k3", "childValue2");
    cfg.setString("s3", null, "k5", "childValue3");
    cfg.setString("s3", "ss", "k6", "childValue4");
    pushFactory.create(admin.newIdent(), childTestRepo, "Create Project Level Config", configName, cfg.toText()).to(RefNames.REFS_CONFIG).assertOkStatus();
    ProjectState state = projectCache.get(childProject).get();
    Config expectedCfg = new Config();
    expectedCfg.setStringList("s1", null, "k1", Arrays.asList("childValue1", "parentValue1"));
    expectedCfg.setString("s1", null, "k2", "parentValue2");
    expectedCfg.setStringList("s2", "ss", "k3", Arrays.asList("childValue2", "parentValue3"));
    expectedCfg.setString("s2", "ss", "k4", "parentValue4");
    expectedCfg.setString("s3", null, "k5", "childValue3");
    expectedCfg.setString("s3", "ss", "k6", "childValue4");
    assertThat(state.getConfig(configName).getWithInheritance(/* merge= */
    true).toText()).isEqualTo(expectedCfg.toText());
    assertThat(state.getConfig(configName).get().toText()).isEqualTo(cfg.toText());
}
Also used : Project(com.google.gerrit.entities.Project) Config(org.eclipse.jgit.lib.Config) ProjectState(com.google.gerrit.server.project.ProjectState) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 17 with ProjectState

use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.

the class ProjectLevelConfigIT method accessProjectSpecificConfig.

@Test
public void accessProjectSpecificConfig() throws Exception {
    String configName = "test.config";
    Config cfg = new Config();
    cfg.setString("s1", null, "k1", "v1");
    cfg.setString("s2", "ss", "k2", "v2");
    PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, "Create Project Level Config", configName, cfg.toText());
    push.to(RefNames.REFS_CONFIG);
    ProjectState state = projectCache.get(project).get();
    assertThat(state.getConfig(configName).get().toText()).isEqualTo(cfg.toText());
}
Also used : Config(org.eclipse.jgit.lib.Config) ProjectState(com.google.gerrit.server.project.ProjectState) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 18 with ProjectState

use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.

the class SubmitWithStickyApprovalDiff method getLatestApprovedPatchsetId.

private PatchSet.Id getLatestApprovedPatchsetId(ChangeNotes notes) {
    ProjectState projectState = projectCache.get(notes.getProjectName()).orElseThrow(illegalState(notes.getProjectName()));
    PatchSet.Id maxPatchSetId = PatchSet.id(notes.getChangeId(), 1);
    for (PatchSetApproval patchSetApproval : notes.getApprovals().values()) {
        if (!patchSetApproval.label().equals(LabelId.CODE_REVIEW)) {
            continue;
        }
        Optional<LabelType> lt = projectState.getLabelTypes(notes).byLabel(patchSetApproval.labelId());
        if (!lt.isPresent() || !lt.get().isMaxPositive(patchSetApproval)) {
            continue;
        }
        if (patchSetApproval.patchSetId().get() > maxPatchSetId.get()) {
            maxPatchSetId = patchSetApproval.patchSetId();
        }
    }
    return maxPatchSetId;
}
Also used : LabelType(com.google.gerrit.entities.LabelType) ProjectState(com.google.gerrit.server.project.ProjectState) PatchSet(com.google.gerrit.entities.PatchSet) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval)

Example 19 with ProjectState

use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.

the class ListDashboards method apply.

@Override
public Response<List<?>> apply(ProjectResource rsrc) throws ResourceNotFoundException, IOException, PermissionBackendException {
    String project = rsrc.getName();
    if (!inherited) {
        return Response.ok(scan(rsrc.getProjectState(), project, true));
    }
    List<List<DashboardInfo>> all = new ArrayList<>();
    boolean setDefault = true;
    for (ProjectState ps : tree(rsrc)) {
        List<DashboardInfo> list = scan(ps, project, setDefault);
        for (DashboardInfo d : list) {
            if (d.isDefault != null && Boolean.TRUE.equals(d.isDefault)) {
                setDefault = false;
            }
        }
        if (!list.isEmpty()) {
            all.add(list);
        }
    }
    return Response.ok(all);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ProjectState(com.google.gerrit.server.project.ProjectState) DashboardInfo(com.google.gerrit.extensions.api.projects.DashboardInfo)

Example 20 with ProjectState

use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.

the class ListDashboards method tree.

private Collection<ProjectState> tree(ProjectResource rsrc) throws PermissionBackendException {
    Map<Project.NameKey, ProjectState> tree = new LinkedHashMap<>();
    for (ProjectState ps : rsrc.getProjectState().tree()) {
        if (ps.statePermitsRead()) {
            tree.put(ps.getNameKey(), ps);
        }
    }
    tree.keySet().retainAll(permissionBackend.currentUser().filter(ProjectPermission.ACCESS, tree.keySet()));
    return tree.values();
}
Also used : ProjectState(com.google.gerrit.server.project.ProjectState) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ProjectState (com.google.gerrit.server.project.ProjectState)86 Project (com.google.gerrit.entities.Project)20 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)19 IOException (java.io.IOException)18 Repository (org.eclipse.jgit.lib.Repository)18 AuthException (com.google.gerrit.extensions.restapi.AuthException)16 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)14 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)14 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 Change (com.google.gerrit.entities.Change)13 ObjectId (org.eclipse.jgit.lib.ObjectId)13 Test (org.junit.Test)13 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)12 ChangeData (com.google.gerrit.server.query.change.ChangeData)11 Inject (com.google.inject.Inject)10 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)10 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)10 StorageException (com.google.gerrit.exceptions.StorageException)9 ProjectInfo (com.google.gerrit.extensions.common.ProjectInfo)9 ProjectResource (com.google.gerrit.server.project.ProjectResource)9