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());
}
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());
}
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;
}
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);
}
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();
}
Aggregations