Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,23 @@
"category": "OpenShift"
}
],
"keybindings": [
{
"command": "openshift.explorer.login",
"key": "alt+shift+l",
"mac": "ctrl+shift+l"
},
{
"command": "openshift.explorer.refresh",
Comment thread
sudhirverma marked this conversation as resolved.
Outdated
"key": "alt+shift+r",
"mac": "ctrl+shift+r"
},
{
"command": "openshift.component.push",
"key": "alt+shift+p",
"mac": "ctrl+shift+p"
}
],
"viewsContainers": {
"activitybar": [
{
Expand Down
27 changes: 21 additions & 6 deletions src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { V1ServicePort, V1Service } from '@kubernetes/client-node';
import { isURL } from 'validator';
import { Refs, Ref, Type } from '../util/refs';
import { Delayer } from '../util/async';
import { contextGlobalState } from '../extension';

export class Component extends OpenShiftItem {

Expand Down Expand Up @@ -148,13 +149,27 @@ export class Component extends OpenShiftItem {
);
}

static getPushCmd(): Thenable< string | undefined> {
return contextGlobalState.globalState.get('PUSH');
}

static setPushCmd(component, application, project): Thenable<void> {
return contextGlobalState.globalState.update('PUSH', `odo push ${component} --app ${application} --project ${project}`);
}

static async push(context: OpenShiftObject): Promise<string> {
const component = await Component.getOpenShiftCmdData(context,
"In which Project you want to push the changes",
"In which Application you want to push the changes",
"For which Component you want to push the changes");
if (!component) return null;
Component.odo.executeInTerminal(Command.pushComponent(component.getParent().getParent().getName(), component.getParent().getName(), component.getName()));
const getPushCmd = await Component.getPushCmd();
if (getPushCmd && !context) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this check in place there is no way to use push command from command palette. After first push it will always push the same component until context menu for component in tree is used.
You need to create new command 'OpenShift: Repeat last push command'.

Component.odo.executeInTerminal(getPushCmd);
} else {
const component = await Component.getOpenShiftCmdData(context,
"In which Project you want to push the changes",
"In which Application you want to push the changes",
"For which Component you want to push the changes");
if (!component) return null;
Component.setPushCmd(component.getName(), component.getParent().getName(), component.getParent().getParent().getName());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be just saving

() => {
    Component.odo.executeInTerminal(Command.pushComponent(component.getParent().getParent().getName(), component.getParent().getName(), component.getName()));
}

here.

Component.odo.executeInTerminal(Command.pushComponent(component.getParent().getParent().getName(), component.getParent().getName(), component.getName()));
}
}

static async watch(context: OpenShiftObject): Promise<void> {
Expand Down
11 changes: 11 additions & 0 deletions test/openshift/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as Util from '../../src/util/async';
import { Refs } from '../../src/util/refs';
import { OpenShiftItem } from '../../src/openshift/openshiftItem';
import pq = require('proxyquire');
import { contextGlobalState } from '../../src/extension';

const expect = chai.expect;
chai.use(sinonChai);
Expand Down Expand Up @@ -664,12 +665,15 @@ suite('OpenShift/Component', () => {
});

suite('push', () => {
let getpushStub;

setup(() => {
quickPickStub = sandbox.stub(vscode.window, 'showQuickPick');
quickPickStub.onFirstCall().resolves(projectItem);
quickPickStub.onSecondCall().resolves(appItem);
quickPickStub.onThirdCall().resolves(componentItem);
getpushStub = sandbox.stub(Component, 'getPushCmd').resolves(undefined);
sandbox.stub(Component, 'setPushCmd');
});

test('returns null when cancelled', async () => {
Expand All @@ -690,6 +694,13 @@ suite('OpenShift/Component', () => {

expect(termStub).calledOnceWith(Command.pushComponent(projectItem.getName(), appItem.getName(), componentItem.getName()));
});

test('works from keybinding', async () => {
getpushStub.resolves(`odo push ${componentItem.getName()} --app ${appItem.getName()} --project ${projectItem.getName()}`);
await Component.push(null);

expect(termStub).calledOnceWith(Command.pushComponent(projectItem.getName(), appItem.getName(), componentItem.getName()));
});
});

suite('watch', () => {
Expand Down