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