Search in sources :

Example 16 with ActionMessage

use of com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage in project intellij-tekton by redhat-developer.

the class CreateTaskRunTemplateAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
    ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_CRUD + "create task run");
    ParentableNode element = getElement(selected);
    String namespace = element.getNamespace();
    ExecHelper.submit(() -> {
        Notification notification;
        TaskConfigurationModel model;
        try {
            model = getModel(element, namespace, tkncli);
        } catch (IOException e) {
            String errorMessage = "Failed to create TaskRun templace from " + element.getName() + " in namespace " + namespace + "An error occurred while retrieving information.\n" + e.getLocalizedMessage();
            telemetry.error(anonymizeResource(element.getName(), namespace, errorMessage)).send();
            UIHelper.executeInUI(() -> {
                Messages.showErrorDialog(errorMessage, "Error");
            });
            logger.warn("Error: " + e.getLocalizedMessage(), e);
            return;
        }
        if (!model.isValid()) {
            String errorMessage = "Failed to create a TaskRun templace from " + element.getName() + " in namespace " + namespace + ". The task is not valid.";
            telemetry.error(anonymizeResource(element.getName(), namespace, errorMessage)).send();
            UIHelper.executeInUI(() -> Messages.showErrorDialog(errorMessage, "Error"));
            return;
        }
        try {
            String contentTask = new YAMLMapper().writeValueAsString(YAMLBuilder.createTaskRun(model));
            openEditor(anActionEvent.getProject(), namespace, telemetry, model, contentTask);
        } catch (IOException e) {
            String errorMessage = "Failed to create TaskRun templace from" + element.getName() + " in namespace " + namespace + " \n" + e.getLocalizedMessage();
            telemetry.error(anonymizeResource(element.getName(), namespace, errorMessage)).send();
            notification = new Notification(NOTIFICATION_ID, "Error", errorMessage, NotificationType.ERROR);
            Notifications.Bus.notify(notification);
            logger.warn(errorMessage, e);
        }
    });
}
Also used : YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) TaskConfigurationModel(com.redhat.devtools.intellij.tektoncd.utils.model.resources.TaskConfigurationModel) IOException(java.io.IOException) Notification(com.intellij.notification.Notification)

Example 17 with ActionMessage

use of com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage in project intellij-tekton by redhat-developer.

the class CreateResourceAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
    ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_CRUD + "create resource");
    ResourcesNode item = getElement(selected);
    String namespace = item.getParent().getName();
    String content = getSnippet("Tekton: PipelineResource");
    if (Strings.isNullOrEmpty(content)) {
        telemetry.error("snippet content empty").send();
    } else {
        String name = namespace + "-newresource.yaml";
        try {
            VirtualFileHelper.createAndOpenVirtualFile(anActionEvent.getProject(), namespace, name, content, KIND_RESOURCES, item);
            telemetry.success().send();
        } catch (IOException e) {
            telemetry.error(anonymizeResource(name, namespace, e.getMessage())).send();
            logger.warn("Could not create resource: " + e.getLocalizedMessage(), e);
        }
    }
}
Also used : ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) IOException(java.io.IOException) ResourcesNode(com.redhat.devtools.intellij.tektoncd.tree.ResourcesNode)

Example 18 with ActionMessage

use of com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage in project intellij-tekton by redhat-developer.

the class CreateTaskAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
    ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_CRUD + "create task").property(PROP_RESOURCE_KIND, KIND_TASK);
    TasksNode item = getElement(selected);
    String namespace = item.getParent().getName();
    String content = getSnippet("Tekton: Task");
    if (Strings.isNullOrEmpty(content)) {
        telemetry.error("snippet content empty").send();
    } else {
        String name = namespace + "-newtask.yaml";
        try {
            VirtualFileHelper.createAndOpenVirtualFile(anActionEvent.getProject(), namespace, name, content, KIND_TASKS, item);
            telemetry.send();
        } catch (IOException e) {
            telemetry.error(anonymizeResource(name, namespace, e.getMessage())).send();
            logger.warn(e.getLocalizedMessage(), e);
        }
    }
}
Also used : TasksNode(com.redhat.devtools.intellij.tektoncd.tree.TasksNode) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) IOException(java.io.IOException)

Example 19 with ActionMessage

use of com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage in project intellij-tekton by redhat-developer.

the class CreateConditionAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
    ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_CRUD + "create condition").property(PROP_RESOURCE_KIND, KIND_CONDITION);
    ConditionsNode item = getElement(selected);
    String namespace = item.getParent().getName();
    String content = getSnippet("Tekton: Condition");
    if (Strings.isNullOrEmpty(content)) {
        telemetry.error("snippet content empty.").send();
    } else {
        String name = namespace + "-newcondition.yaml";
        try {
            VirtualFileHelper.createAndOpenVirtualFile(anActionEvent.getProject(), namespace, name, content, KIND_CONDITIONS, item);
            telemetry.send();
        } catch (IOException e) {
            telemetry.error(anonymizeResource(name, namespace, e.getMessage())).send();
            logger.warn("Could not create condition: " + e.getLocalizedMessage(), e);
        }
    }
}
Also used : ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) IOException(java.io.IOException) ConditionsNode(com.redhat.devtools.intellij.tektoncd.tree.ConditionsNode)

Example 20 with ActionMessage

use of com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage in project intellij-redhat-telemetry by redhat-developer.

the class TelemetryMessageBuilderTest method property_should_ignore_property_with_null_value.

@Test
public void property_should_ignore_property_with_null_value() {
    // given
    ActionMessage message = builder.action("smurfette");
    int beforeAdding = message.properties().size();
    // when
    message.property("likes", null);
    // then
    assertThat(message.properties().size()).isEqualTo(beforeAdding);
}
Also used : ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) Test(org.junit.jupiter.api.Test)

Aggregations

ActionMessage (com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage)39 Test (org.junit.jupiter.api.Test)26 IOException (java.io.IOException)11 ParentableNode (com.redhat.devtools.intellij.tektoncd.tree.ParentableNode)6 Notification (com.intellij.notification.Notification)3 PipelineRunNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode)3 TaskRunNode (com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode)3 Tkn (com.redhat.devtools.intellij.tektoncd.tkn.Tkn)2 PipelineNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineNode)2 TektonTreeStructure (com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure)2 Duration (java.time.Duration)2 LocalDateTime (java.time.LocalDateTime)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Project (com.intellij.openapi.project.Project)1 Messages (com.intellij.openapi.ui.Messages)1 GenericResource (com.redhat.devtools.intellij.common.model.GenericResource)1 ExecHelper (com.redhat.devtools.intellij.common.utils.ExecHelper)1 UIHelper (com.redhat.devtools.intellij.common.utils.UIHelper)1