Search in sources :

Example 1 with DescriptionInput

use of com.google.gerrit.extensions.api.projects.DescriptionInput in project gerrit by GerritCodeReview.

the class ProjectIT method descriptionChangeCausesRefUpdate.

@Test
public void descriptionChangeCausesRefUpdate() throws Exception {
    RevCommit initialHead = getRemoteHead(project, RefNames.REFS_CONFIG);
    assertThat(gApi.projects().name(project.get()).description()).isEmpty();
    DescriptionInput in = new DescriptionInput();
    in.description = "new project description";
    gApi.projects().name(project.get()).description(in);
    assertThat(gApi.projects().name(project.get()).description()).isEqualTo(in.description);
    RevCommit updatedHead = getRemoteHead(project, RefNames.REFS_CONFIG);
    eventRecorder.assertRefUpdatedEvents(project.get(), RefNames.REFS_CONFIG, initialHead, updatedHead);
}
Also used : DescriptionInput(com.google.gerrit.extensions.api.projects.DescriptionInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with DescriptionInput

use of com.google.gerrit.extensions.api.projects.DescriptionInput in project gerrit by GerritCodeReview.

the class ProjectIT method descriptionIsDeletedWhenNotSpecified.

@Test
public void descriptionIsDeletedWhenNotSpecified() throws Exception {
    assertThat(gApi.projects().name(project.get()).description()).isEmpty();
    DescriptionInput in = new DescriptionInput();
    in.description = "new project description";
    gApi.projects().name(project.get()).description(in);
    assertThat(gApi.projects().name(project.get()).description()).isEqualTo(in.description);
    in.description = null;
    gApi.projects().name(project.get()).description(in);
    assertThat(gApi.projects().name(project.get()).description()).isEmpty();
}
Also used : DescriptionInput(com.google.gerrit.extensions.api.projects.DescriptionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with DescriptionInput

use of com.google.gerrit.extensions.api.projects.DescriptionInput in project gerrit by GerritCodeReview.

the class PutDescription method apply.

@Override
public Response<String> apply(ProjectResource resource, DescriptionInput input) throws AuthException, ResourceConflictException, ResourceNotFoundException, IOException {
    if (input == null) {
        // Delete would set description to null.
        input = new DescriptionInput();
    }
    ProjectControl ctl = resource.getControl();
    IdentifiedUser user = ctl.getUser().asIdentifiedUser();
    if (!ctl.isOwner()) {
        throw new AuthException("not project owner");
    }
    try (MetaDataUpdate md = updateFactory.create(resource.getNameKey())) {
        ProjectConfig config = ProjectConfig.read(md);
        Project project = config.getProject();
        project.setDescription(Strings.emptyToNull(input.description));
        String msg = MoreObjects.firstNonNull(Strings.emptyToNull(input.commitMessage), "Updated description.\n");
        if (!msg.endsWith("\n")) {
            msg += "\n";
        }
        md.setAuthor(user);
        md.setMessage(msg);
        config.commit(md);
        cache.evict(ctl.getProject());
        md.getRepository().setGitwebDescription(project.getDescription());
        return Strings.isNullOrEmpty(project.getDescription()) ? Response.<String>none() : Response.ok(project.getDescription());
    } catch (RepositoryNotFoundException notFound) {
        throw new ResourceNotFoundException(resource.getName());
    } catch (ConfigInvalidException e) {
        throw new ResourceConflictException(String.format("invalid project.config: %s", e.getMessage()));
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Project(com.google.gerrit.reviewdb.client.Project) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) DescriptionInput(com.google.gerrit.extensions.api.projects.DescriptionInput) AuthException(com.google.gerrit.extensions.restapi.AuthException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Aggregations

DescriptionInput (com.google.gerrit.extensions.api.projects.DescriptionInput)3 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 Test (org.junit.Test)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 Project (com.google.gerrit.reviewdb.client.Project)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)1 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1