use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.
the class ProjectsImpl method create.
@Override
public ProjectApi create(String name) throws RestApiException {
ProjectInput in = new ProjectInput();
in.name = name;
return create(in);
}
use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.
the class CreateProjectCommand method run.
@Override
protected void run() throws Failure {
try {
if (!suggestParent) {
if (projectName == null) {
throw die("Project name is required.");
}
ProjectInput input = new ProjectInput();
input.name = projectName;
if (ownerIds != null) {
input.owners = Lists.transform(ownerIds, AccountGroup.UUID::get);
}
if (newParent != null) {
input.parent = newParent.getProject().getName();
}
input.permissionsOnly = permissionsOnly;
input.description = projectDescription;
input.submitType = submitType;
input.useContributorAgreements = contributorAgreements;
input.useSignedOffBy = signedOffBy;
input.useContentMerge = contentMerge;
input.requireChangeId = requireChangeID;
input.createNewChangeForAllNotInTarget = createNewChangeForAllNotInTarget;
input.branches = branch;
input.createEmptyCommit = createEmptyCommit;
input.maxObjectSizeLimit = maxObjectSizeLimit;
if (pluginConfigValues != null) {
input.pluginConfigValues = parsePluginConfigValues(pluginConfigValues);
}
gApi.projects().create(input);
} else {
for (Project.NameKey parent : suggestParentCandidates.getNameKeys()) {
stdout.print(parent.get() + '\n');
}
}
} catch (RestApiException err) {
throw die(err);
} catch (PermissionBackendException err) {
throw new Failure(1, "permissions unavailable", err);
}
}
use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.
the class ConfigChangeIT method onlyAdminMayUpdateProjectParent.
@Test
@TestProjectInput(cloneAs = "user")
public void onlyAdminMayUpdateProjectParent() throws Exception {
setApiUser(admin);
ProjectInput parent = new ProjectInput();
parent.name = name("parent");
parent.permissionsOnly = true;
gApi.projects().create(parent);
setApiUser(user);
Config cfg = readProjectConfig();
assertThat(cfg.getString("access", null, "inheritFrom")).isAnyOf(null, allProjects.get());
cfg.setString("access", null, "inheritFrom", parent.name);
PushOneCommit.Result r = createConfigChange(cfg);
String id = r.getChangeId();
gApi.changes().id(id).current().review(ReviewInput.approve());
try {
gApi.changes().id(id).current().submit();
fail("expected submit to fail");
} catch (ResourceConflictException e) {
int n = gApi.changes().id(id).info()._number;
assertThat(e).hasMessageThat().isEqualTo("Failed to submit 1 change due to the following problems:\n" + "Change " + n + ": Change contains a project configuration that" + " changes the parent project.\n" + "The change must be submitted by a Gerrit administrator.");
}
assertThat(gApi.projects().name(project.get()).get().parent).isEqualTo(allProjects.get());
fetchRefsMetaConfig();
assertThat(readProjectConfig().getString("access", null, "inheritFrom")).isAnyOf(null, allProjects.get());
setApiUser(admin);
gApi.changes().id(id).current().submit();
assertThat(gApi.changes().id(id).info().status).isEqualTo(ChangeStatus.MERGED);
assertThat(gApi.projects().name(project.get()).get().parent).isEqualTo(parent.name);
fetchRefsMetaConfig();
assertThat(readProjectConfig().getString("access", null, "inheritFrom")).isEqualTo(parent.name);
}
use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method projectInput.
private ProjectInput projectInput(Description description) {
ProjectInput in = new ProjectInput();
TestProjectInput ann = description.getAnnotation(TestProjectInput.class);
in.name = name("project");
if (ann != null) {
in.parent = Strings.emptyToNull(ann.parent());
in.description = Strings.emptyToNull(ann.description());
in.createEmptyCommit = ann.createEmptyCommit();
in.submitType = ann.submitType();
in.useContentMerge = ann.useContributorAgreements();
in.useSignedOffBy = ann.useSignedOffBy();
in.useContentMerge = ann.useContentMerge();
} else {
// Defaults should match TestProjectConfig, omitting nullable values.
in.createEmptyCommit = true;
}
updateProjectInput(in);
return in;
}
use of com.google.gerrit.extensions.api.projects.ProjectInput in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method createProject.
protected Project.NameKey createProject(String nameSuffix, Project.NameKey parent, boolean createEmptyCommit, SubmitType submitType) throws RestApiException {
ProjectInput in = new ProjectInput();
in.name = name(nameSuffix);
in.parent = parent != null ? parent.get() : null;
in.submitType = submitType;
in.createEmptyCommit = createEmptyCommit;
return createProject(in);
}
Aggregations