Search in sources :

Example 11 with ProjectInput

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);
}
Also used : ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput)

Example 12 with ProjectInput

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);
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 13 with ProjectInput

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);
}
Also used : TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Config(org.eclipse.jgit.lib.Config) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 14 with ProjectInput

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;
}
Also used : ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput)

Example 15 with ProjectInput

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);
}
Also used : ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput)

Aggregations

ProjectInput (com.google.gerrit.extensions.api.projects.ProjectInput)24 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)19 Test (org.junit.Test)19 Project (com.google.gerrit.reviewdb.client.Project)6 ProjectAssert.assertProjectInfo (com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjectInfo)3 ProjectInfo (com.google.gerrit.extensions.common.ProjectInfo)3 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)2 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)1 ConfigInput (com.google.gerrit.extensions.api.projects.ConfigInput)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)1 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 ProjectState (com.google.gerrit.server.project.ProjectState)1 ProjectCreationValidationListener (com.google.gerrit.server.validators.ProjectCreationValidationListener)1 ValidationException (com.google.gerrit.server.validators.ValidationException)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1