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

use vscode open command instead of open module for external links #1254

Merged
merged 3 commits into from
Oct 31, 2019
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
25 changes: 16 additions & 9 deletions src/k8s/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import * as vscode from 'vscode';
import { Command } from "../odo";
import { KubeConfigUtils } from "../util/kubeUtils";
import open = require("open");
import { OpenShiftItem } from '../openshift/openshiftItem';

const k8sConfig = new KubeConfigUtils();
Expand All @@ -33,54 +32,62 @@ export class Console extends OpenShiftItem {
}

static async openBuildConfig(context: { id: any; }) {
let url = '';
if (!context) {
vscode.window.showErrorMessage("Cannot load the build config");
return;
}
const consoleUrl = await Console.fetchOpenshiftConsoleUrl();
if (await Console.fetchClusterVersion() === null) {
return await open(`${consoleUrl}/k8s/ns/${context.id}/buildconfigs`);
url = `${consoleUrl}/k8s/ns/${context.id}/buildconfigs`;
} else {
return await open(`${clusterUrl}/console/project/${project}/browse/builds/${context.id}?tab=history`);
url = `${clusterUrl}/console/project/${project}/browse/builds/${context.id}?tab=history`;
}
return vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
}

static async openDeploymentConfig(context: { id: any; }) {
let url = '';
if (!context) {
vscode.window.showErrorMessage("Cannot load the deployment config");
return;
}
const consoleUrl = await Console.fetchOpenshiftConsoleUrl();
if (await Console.fetchClusterVersion() === null) {
return await open(`${consoleUrl}/k8s/ns/${context.id}/deploymentconfigs`);
url = `${consoleUrl}/k8s/ns/${context.id}/deploymentconfigs`;
} else {
return await open(`${clusterUrl}/console/project/${project}/browse/dc/${context.id}?tab=history`);
url = `${clusterUrl}/console/project/${project}/browse/dc/${context.id}?tab=history`;
}
return vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
}

static async openImageStream(context: { id: any; }) {
let url = '';
if (!context) {
vscode.window.showErrorMessage("Cannot load the image stream");
return;
}
const consoleUrl = await this.fetchOpenshiftConsoleUrl();
if (await Console.fetchClusterVersion() === null) {
return await open(`${consoleUrl}/k8s/ns/${context.id}/imagestreams`);
url = `${consoleUrl}/k8s/ns/${context.id}/imagestreams`;
} else {
return await open(`${clusterUrl}/console/project/${project}/browse/images/${context.id}?tab=history`);
url = `${clusterUrl}/console/project/${project}/browse/images/${context.id}?tab=history`;
}
return vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
}

static async openProject(context: { id: any; }) {
let url = '';
if (!context) {
vscode.window.showErrorMessage("Cannot load the Project");
return;
}
const consoleUrl = await Console.fetchOpenshiftConsoleUrl();
if (await Console.fetchClusterVersion() === null) {
return await open(`${consoleUrl}/overview/ns/${context.id}`);
url = `${consoleUrl}/overview/ns/${context.id}`;
} else {
return await open(`${consoleUrl}/console/project/${context.id}/overview`);
url = `${consoleUrl}/console/project/${context.id}/overview`;
}
return vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
}
}
3 changes: 1 addition & 2 deletions src/odo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import * as odo from './odo/config';
import { ComponentSettings } from './odo/config';
import { GlyphChars } from './util/constants';
import { Subject } from 'rxjs';
import open = require('open');
import { Progress } from './util/progress';
import { V1ServicePort, V1Service } from '@kubernetes/client-node';

Expand Down Expand Up @@ -1134,7 +1133,7 @@ export class OdoImpl implements Odo {
if (projectsToMigrate.length > 0) {
const choice = await window.showWarningMessage(`Some of the resources in cluster must be updated to work with latest release of OpenShift Connector Extension.`, 'Update', 'Don\'t check again', 'Help', 'Cancel');
if (choice === 'Help') {
open('https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0');
commands.executeCommand('vscode.open', Uri.parse(`https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0`));
this.subject.next(new OdoEventImpl('changed', this.getClusters()[0]));
} else if (choice === 'Don\'t check again') {
workspace.getConfiguration("openshiftConnector").update("disableCheckForMigration", true, true);
Expand Down
5 changes: 2 additions & 3 deletions src/openshift/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

import { Command } from "../odo";
import { OpenShiftItem } from './openshiftItem';
import { window, commands, env, QuickPickItem, ExtensionContext } from 'vscode';
import { window, commands, env, QuickPickItem, ExtensionContext, Uri } from 'vscode';
import { CliExitData, Cli } from "../cli";
import open = require("open");
import { TokenStore } from "../util/credentialManager";
import { KubeConfigUtils } from '../util/kubeUtils';
import { Filters } from "../util/filters";
Expand Down Expand Up @@ -69,7 +68,7 @@ export class Cluster extends OpenShiftItem {
const serverUrl = await Cluster.odo.execute(Command.showServerUrl());
consoleUrl = `${serverUrl.stdout}/console`;
}
open(consoleUrl);
return commands.executeCommand('vscode.open', Uri.parse(consoleUrl));
}

static async switchContext() {
Expand Down
7 changes: 3 additions & 4 deletions src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { OpenShiftItem } from './openshiftItem';
import { OpenShiftObject, Command, ContextType, ComponentType } from '../odo';
import { window, commands, QuickPickItem, Uri, workspace, ExtensionContext } from 'vscode';
import { Progress } from '../util/progress';
import open = require('open');
import { ChildProcess } from 'child_process';
import { CliExitData } from '../cli';
import { isURL } from 'validator';
Expand Down Expand Up @@ -294,7 +293,7 @@ export class Component extends OpenShiftItem {
await Component.undeploy(component);
return null;
case 'Help':
open('https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0');
commands.executeCommand('vscode.open', Uri.parse(`https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0`));
break;
case 'Cancel':
return null;
Expand Down Expand Up @@ -352,9 +351,9 @@ export class Component extends OpenShiftItem {
if (hostName.length >1) {
selectRoute = await window.showQuickPick(hostName, {placeHolder: "This Component has multiple URLs. Select the desired URL to open in browser."});
if (!selectRoute) return null;
return open(`${selectRoute.label}`);
return commands.executeCommand('vscode.open', Uri.parse(`${selectRoute.label}`));
} else {
return open(`${hostName[0].label}`);
return commands.executeCommand('vscode.open', Uri.parse(`${hostName[0].label}`));
}
} else if (unpushedUrl.length > 0) {
return `${unpushedUrl.length} unpushed URL in the local config. Use \'Push\' command before opening URL in browser.`;
Expand Down
5 changes: 2 additions & 3 deletions src/openshift/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
*-----------------------------------------------------------------------------------------------*/

import { OpenShiftObject, Command } from '../odo';
import { window, QuickPickItem } from 'vscode';
import { window, QuickPickItem, commands, Uri } from 'vscode';
import { V1ServicePort } from '@kubernetes/client-node';
import { OpenShiftItem } from './openshiftItem';
import { Progress } from "../util/progress";
import open = require('open');
import { ChildProcess } from 'child_process';

export class Url extends OpenShiftItem{
Expand Down Expand Up @@ -80,7 +79,7 @@ export class Url extends OpenShiftItem{
urlObject = result.filter((value) => (value.metadata.name === treeItem.getName()));
}
if (urlObject[0].status.state === 'Pushed') {
open(`${urlObject[0].spec.protocol}://${urlObject[0].spec.host}`);
return commands.executeCommand('vscode.open', Uri.parse(`${urlObject[0].spec.protocol}://${urlObject[0].spec.host}`));
} else {
window.showInformationMessage('Selected URL is not created in cluster. Use \'Push\' command before opening URL in browser.');
}
Expand Down
3 changes: 1 addition & 2 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Archive } from "./util/archive";
import { which } from "shelljs";
import { DownloadUtil } from "./util/download";
import hasha = require("hasha");
import open = require("open");
import * as vscode from 'vscode';
import * as path from 'path';
import * as fsex from 'fs-extra';
Expand Down Expand Up @@ -94,7 +93,7 @@ export class ToolsConfig {
toolLocation = toolCacheLocation;
}
} else if (response === `Help`) {
open('https://github.com/redhat-developer/vscode-openshift-tools#dependencies');
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(`https://github.com/redhat-developer/vscode-openshift-tools#dependencies`));
}
}
if (toolLocation) {
Expand Down
18 changes: 7 additions & 11 deletions test/unit/openshift/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,15 @@ suite('OpenShift/Component', () => {
let getProjects: sinon.SinonStub;
let getApps: sinon.SinonStub;
let Component: any;
let opnStub: sinon.SinonStub;
let infoStub: sinon.SinonStub;
let fetchTag: sinon.SinonStub;
let commandStub: sinon.SinonStub;

setup(() => {
sandbox = sinon.createSandbox();
opnStub = sandbox.stub();
sandbox.stub(vscode.workspace, "updateWorkspaceFolders");
fetchTag = sandbox.stub(Refs, 'fetchTag').resolves (new Map<string, string>([['HEAD', 'shanumb']]));
Component = pq('../../../src/openshift/component', {
open: opnStub
}).Component;
Component = pq('../../../src/openshift/component', {}).Component;
termStub = sandbox.stub(OdoImpl.prototype, 'executeInTerminal');
execStub = sandbox.stub(OdoImpl.prototype, 'execute').resolves({ stdout: "" });
sandbox.stub(OdoImpl.prototype, 'getServices');
Expand Down Expand Up @@ -1127,7 +1123,7 @@ suite('OpenShift/Component', () => {
showWarningMessageStub.onSecondCall().resolves(undefined);
const result = await Component.push(componentItem);

expect(opnStub).calledOnceWith('https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0');
expect(commandStub).calledOnceWith('vscode.open', vscode.Uri.parse('https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0'));
expect(result).null;
});
});
Expand Down Expand Up @@ -1192,7 +1188,7 @@ suite('OpenShift/Component', () => {
]
}), stderr: ''});
await Component.openUrl(null);
expect(opnStub).calledOnceWith('https://url');
expect(commandStub).calledOnceWith('vscode.open', vscode.Uri.parse('https://url'));
});

test('gets URLs for the component and if there is more than one asks which one to open it in browser and opens selected', async () => {
Expand Down Expand Up @@ -1221,7 +1217,7 @@ suite('OpenShift/Component', () => {
]
}), stderr: ''});
await Component.openUrl(null);
expect(opnStub).calledOnceWith('https://url1');
expect(commandStub).calledOnceWith('vscode.open', vscode.Uri.parse('https://url1'));
});

test('gets URLs for the component, if there is more than one asks which one to open it in browser and exits if selection is canceled', async () => {
Expand Down Expand Up @@ -1250,7 +1246,7 @@ suite('OpenShift/Component', () => {
]
}), stderr: ''});
await Component.openUrl(null);
expect(opnStub.callCount).equals(0);
expect(commandStub.callCount).equals(0);
});

test('request to create url for component if it does not exist, creates the URL if confirmed by user and opens it in browser.' , async () => {
Expand All @@ -1271,14 +1267,14 @@ suite('OpenShift/Component', () => {
]
}), stderr: ''});
await Component.openUrl(null);
expect(opnStub).calledOnceWith('https://url');
expect(commandStub).calledOnceWith('vscode.open', vscode.Uri.parse('https://url'));
});

test('request to create url for component if it does not exist and exits when not confirmed' , async () => {
sandbox.stub(vscode.window, 'showInformationMessage').resolves('Cancel');
sandbox.stub(Component, 'listUrl').resolves(null);
await Component.openUrl(null);
expect(opnStub).is.not.called;
expect(commandStub).is.not.called;
});

test('request to create url for component if it does not exist' , async () => {
Expand Down