Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add/remove/edit helm repo (#673, #803) #795

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ dependencies {
'org.junit.platform:junit-platform-launcher:1.10.2',
'org.mockito:mockito-core:5.11.0',
'org.easytesting:fest-assert:1.4',
'com.redhat.devtools.intellij:intellij-common:1.9.5:test',
'com.redhat.devtools.intellij:intellij-common:1.9.6-SNAPSHOT:test',
'org.awaitility:awaitility:4.2.1',
'org.mock-server:mockserver-client-java:5.15.0',
'org.mock-server:mockserver-netty:5.15.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
******************************************************************************/
package org.jboss.tools.intellij.openshift.test.ui.annotations;

import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.Tag;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

import org.junit.jupiter.api.Tag;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @author Ondrej Dockal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.data.RemoteComponent;
import com.intellij.remoterobot.fixtures.*;
import com.intellij.remoterobot.fixtures.ComponentFixture;
import com.intellij.remoterobot.fixtures.ContainerFixture;
import com.intellij.remoterobot.fixtures.DefaultXpath;
import com.intellij.remoterobot.fixtures.FixtureName;
import com.intellij.remoterobot.fixtures.JTreeFixture;
import com.intellij.remoterobot.search.locators.Locator;
import com.intellij.remoterobot.utils.Keyboard;
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static Chart get(String name, Helm helm) throws Exception {
}

public static void addRepository(Pair<String, String> pair, Helm helm) throws IOException {
helm.addRepo(pair.first, pair.second);
helm.addRepo(pair.first, pair.second, null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,59 @@

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;

public class HelmCliRepoTest extends HelmCliTest {

public void testListRepos_should_list_repo_that_was_added() throws IOException {
// given openshift repo was added to helm repos
String name = "openshift";
String url = "https://charts.openshift.io/";
helm.addRepo(name, url);
// when
List<HelmRepository> repositories = helm.listRepos();
// then
boolean found = repositories.stream().anyMatch((HelmRepository repository) ->
repository.getName().equals(name)
&& repository.getUrl().equals(url)
);
assertTrue(found);
try {
// given openshift repo was added to helm repos
String url = "https://charts.openshift.io/";
helm.addRepo(name, url, null);
// when
List<HelmRepository> repositories = helm.listRepos();
// then
boolean found = repositories.stream().anyMatch((HelmRepository repository) ->
repository.getName().equals(name)
&& repository.getUrl().equals(url)
);
assertTrue(found);
} finally {
silentlyRemoveRepos(name);
}
}

public void testRemoveRepos_should_remove_repo_that_was_added() throws IOException {
String name = "openshift-charts";
String name2 = "openshift-charts2";
try {
// given openshift repo was added to helm repos
helm.addRepo(name, "https://charts.openshift.io/", null);
helm.addRepo(name2, "https://charts.openshift.io/", null);
List<String> helmRepositoryNames = helm.listRepos().stream()
.map(HelmRepository::getName)
.collect(Collectors.toList());
assertThat(helmRepositoryNames).contains(name, name2);
// when
helm.removeRepos(name, name2);
// then
helmRepositoryNames = helm.listRepos().stream()
.map(HelmRepository::getName)
.collect(Collectors.toList());
assertThat(helmRepositoryNames).doesNotContain(name, name2);
} finally {
silentlyRemoveRepos(name, name2);
}
}

private void silentlyRemoveRepos(String... names) {
try {
helm.removeRepos(names);
} catch(Exception e) {
// ignore
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*******************************************************************************
* Copyright (c) 2024 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.intellij.openshift.actions.helm;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.redhat.devtools.intellij.common.utils.ApplicationUtils;
import com.redhat.devtools.intellij.common.utils.SwingUtils;
import java.awt.Point;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import org.jboss.tools.intellij.openshift.actions.HelmAction;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryService;
import org.jboss.tools.intellij.openshift.tree.application.HelmRepositoriesNode;
import org.jboss.tools.intellij.openshift.ui.helm.AddHelmRepoDialog;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
import org.jboss.tools.intellij.openshift.utils.helm.HelmRepository;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class AddHelmRepoAction extends HelmAction {

private static final Logger LOGGER = LoggerFactory.getLogger(AddHelmRepoAction.class);

@Override
public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object selected, @NotNull Helm helm) {
Project project = getEventProject(anActionEvent);
if (!(selected instanceof HelmRepositoriesNode repositoriesNode)) {
return;
}
openAddHelmRepoDialog(repositoriesNode, helm, project, SwingUtils.getMouseLocation(anActionEvent));
}

private void openAddHelmRepoDialog(HelmRepositoriesNode repositoriesNode, Helm helm, Project project, Point location) {
CompletableFuture.supplyAsync(
() -> listRepositories(helm),
ApplicationUtils.PLATFORM_EXECUTOR
).thenAcceptAsync(
repositories -> {
AddHelmRepoDialog dialog = new AddHelmRepoDialog(repositories, repositoriesNode, helm, project, location);
sendTelemetryResults(TelemetryService.TelemetryResult.SUCCESS);
dialog.show();
},
ApplicationUtils.UI_EXECUTOR
);
}

private Collection<HelmRepository> listRepositories(Helm helm) {
try {
return helm.listRepos();
} catch (IOException e) {
LOGGER.warn("Could not list helm repositories", e);
return Collections.emptyList();
}
}

@Override
public String getTelemetryActionName() {
return "helm-add repo";
}

@Override
public boolean isVisible(Object selected) {
return selected instanceof HelmRepositoriesNode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright (c) 2024 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.intellij.openshift.actions.helm;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.redhat.devtools.intellij.common.utils.ApplicationUtils;
import com.redhat.devtools.intellij.common.utils.SwingUtils;
import java.awt.Point;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import org.jboss.tools.intellij.openshift.actions.HelmAction;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryService;
import org.jboss.tools.intellij.openshift.tree.application.HelmRepositoriesNode;
import org.jboss.tools.intellij.openshift.tree.application.HelmRepositoryNode;
import org.jboss.tools.intellij.openshift.ui.helm.EditHelmRepoDialog;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
import org.jboss.tools.intellij.openshift.utils.helm.HelmRepository;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class EditHelmRepoAction extends HelmAction {

private static final Logger LOGGER = LoggerFactory.getLogger(EditHelmRepoAction.class);

@Override
public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object selected, @NotNull Helm helm) {
Project project = getEventProject(anActionEvent);
if (!(selected instanceof HelmRepositoryNode repositoryNode)) {
return;
}
openAddHelmRepoDialog(repositoryNode, repositoryNode.getParent(), helm, project, SwingUtils.getMouseLocation(anActionEvent));
}

private void openAddHelmRepoDialog(HelmRepositoryNode repositoryNode, HelmRepositoriesNode repositoriesNode, Helm helm, Project project, Point location) {
CompletableFuture.supplyAsync(
() -> listRepositories(helm),
ApplicationUtils.PLATFORM_EXECUTOR
).thenAcceptAsync(
repositories -> {
EditHelmRepoDialog dialog = new EditHelmRepoDialog(repositories, repositoryNode, repositoriesNode, helm, project, location);
sendTelemetryResults(TelemetryService.TelemetryResult.SUCCESS);
dialog.show();
},
ApplicationUtils.UI_EXECUTOR
);
}

private Collection<HelmRepository> listRepositories(Helm helm) {
try {
return helm.listRepos();
} catch (IOException e) {
LOGGER.warn("Could not list helm repositories", e);
return Collections.emptyList();
}
}

@Override
public String getTelemetryActionName() {
return "helm-edit repo";
}

@Override
public boolean isVisible(Object selected) {
return selected instanceof HelmRepositoryNode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import org.jboss.tools.intellij.openshift.actions.HelmAction;
import org.jboss.tools.intellij.openshift.actions.NodeUtils;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryService;
import org.jboss.tools.intellij.openshift.tree.application.ApplicationsRootNode;
import org.jboss.tools.intellij.openshift.tree.application.NamespaceNode;
import org.jboss.tools.intellij.openshift.tree.application.ParentableNode;
import org.jboss.tools.intellij.openshift.ui.helm.ChartsDialog;
import org.jboss.tools.intellij.openshift.utils.helm.Helm;
import org.jboss.tools.intellij.openshift.utils.odo.Odo;
Expand All @@ -27,11 +27,10 @@ public class OpenHelmChartsAction extends HelmAction {
@Override
public void actionPerformedOnSelectedObject(AnActionEvent anActionEvent, Object selected, @NotNull Helm helm) {
Project project = getEventProject(anActionEvent);
ParentableNode<?> parentableNode = ((ParentableNode<?>) selected);
if (parentableNode == null) {
ApplicationsRootNode rootNode = NodeUtils.getRoot(selected);
if (rootNode == null) {
return;
}
ApplicationsRootNode rootNode = parentableNode.getRoot();
Odo odo = rootNode.getOdo().getNow(null);
if (odo == null) {
return;
Expand Down
Loading
Loading