Search in sources :

Example 1 with InputWithCommitMessage

use of com.google.gerrit.extensions.common.InputWithCommitMessage in project gerrit by GerritCodeReview.

the class DeleteLabel method apply.

@Override
public Response<?> apply(LabelResource rsrc, InputWithCommitMessage input) throws AuthException, ResourceNotFoundException, PermissionBackendException, IOException, ConfigInvalidException {
    if (!user.get().isIdentifiedUser()) {
        throw new AuthException("Authentication required");
    }
    permissionBackend.currentUser().project(rsrc.getProject().getNameKey()).check(ProjectPermission.WRITE_CONFIG);
    if (input == null) {
        input = new InputWithCommitMessage();
    }
    try (MetaDataUpdate md = updateFactory.create(rsrc.getProject().getNameKey())) {
        ProjectConfig config = projectConfigFactory.read(md);
        if (!deleteLabel(config, rsrc.getLabelType().getName())) {
            throw new ResourceNotFoundException(IdString.fromDecoded(rsrc.getLabelType().getName()));
        }
        if (input.commitMessage != null) {
            md.setMessage(Strings.emptyToNull(input.commitMessage.trim()));
        } else {
            md.setMessage("Delete label");
        }
        config.commit(md);
    }
    projectCache.evictAndReindex(rsrc.getProject().getProjectState().getProject());
    return Response.none();
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) AuthException(com.google.gerrit.extensions.restapi.AuthException) InputWithCommitMessage(com.google.gerrit.extensions.common.InputWithCommitMessage) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Aggregations

InputWithCommitMessage (com.google.gerrit.extensions.common.InputWithCommitMessage)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)1 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)1