All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.split.qos.server.integrations.slack.commands.SlackPauseCommand Maven / Gradle / Ivy

There is a newer version: 22.4.3
Show newest version
package io.split.qos.server.integrations.slack.commands;

import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import com.ullink.slack.simpleslackapi.SlackSession;
import com.ullink.slack.simpleslackapi.events.SlackMessagePosted;
import io.split.qos.server.QOSServerBehaviour;
import io.split.qos.server.integrations.slack.commandintegration.SlackCommand;
import io.split.qos.server.integrations.slack.commandintegration.SlackCommandGetter;
import io.split.qos.server.modules.QOSServerModule;
import io.split.qos.server.util.SlackMessageSender;
import io.split.testrunner.util.SlackColors;

import java.util.List;

/**
 * Pauses the server. No new tests will be added, currently running tests
 * will finish.
 */
@Singleton
public class SlackPauseCommand extends SlackAbstractCommand {
    private final QOSServerBehaviour behaviour;

    @Inject
    public SlackPauseCommand(
            QOSServerBehaviour behaviour,
            SlackCommandGetter slackCommandGetter,
            SlackMessageSender slackMessageSender,
            SlackColors slackColors,
            @Named(QOSServerModule.QOS_SERVER_NAME) String serverName) {
        super(slackColors, serverName, slackMessageSender, slackCommandGetter);
        this.behaviour = behaviour;
    }

    @Override
    public boolean test(SlackMessagePosted messagePosted, SlackSession session) {
        SlackCommand slackCommand = command(messagePosted);
        behaviour.pause(messagePosted.getSender().getUserName());

        messageSender()
                .sendWarning(slackCommand.command(),
                        "Server PAUSED by " + messagePosted.getSender().getUserName(),
                        messagePosted.getChannel(),
                        session);
        return true;
    }

    @Override
    public String description() {
        return "Pauses the tests running for the server. Current tests will keep running";
    }

    @Override
    public String arguments() {
        return "[server-name (optional)] pause";
    }

    @Override
    public boolean acceptsArguments(List arguments) {
        Preconditions.checkNotNull(arguments);
        return arguments.size() == 0;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy