Skip to content

Commit

Permalink
git+binary workflow fix (#1158)
Browse files Browse the repository at this point in the history
* 1. Add context folder selection at start for git workflow
2. Check for component folder already existing

* fix tslint issues

* remove class declaration from workspace.ts

* fix path validation function
  • Loading branch information
mohitsuman authored Sep 13, 2019
1 parent e268b89 commit 79e3a49
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 64 deletions.
66 changes: 8 additions & 58 deletions src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,9 @@ import { Refs, Ref, Type } from '../util/refs';
import { Delayer } from '../util/async';
import { Platform } from '../util/platform';
import path = require('path');
import fs = require('fs-extra');
import globby = require('globby');
import { selectWorkspaceFolder } from '../util/workspace';

interface WorkspaceFolderItem extends QuickPickItem {
uri: Uri;
}

class CreateWorkspaceItem implements QuickPickItem {

constructor() { }

get label(): string { return `$(plus) Add new workspace folder.`; }
get description(): string { return 'Folder which does not have an openshift context'; }

}

export class Component extends OpenShiftItem {
public static extensionContext: ExtensionContext;
static async getOpenshiftData(context: OpenShiftObject): Promise<OpenShiftObject> {
Expand Down Expand Up @@ -426,7 +412,10 @@ export class Component extends OpenShiftItem {
let application: OpenShiftObject = context;
if (!application) application = await Component.getOpenshiftData(context);
if (!application) return null;
const workspacePath = await selectWorkspaceFolder();
if (!workspacePath) return null;
const delayer = new Delayer<string>(500);

const repoURI = await window.showInputBox({
prompt: 'Git repository URI',
validateInput: (value: string) => {
Expand Down Expand Up @@ -459,65 +448,26 @@ export class Component extends OpenShiftItem {

if (!componentTypeVersion) return null;

const folder = await window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
defaultUri: Uri.file(Platform.getUserHomePath()),
openLabel: "Select Context Folder for Component"
});

if (!folder) return null;

window.showInformationMessage('Do you want to clone git repository for created Component?', 'Yes', 'No').then((value) => {
value === 'Yes' && commands.executeCommand('git.clone', repoURI);
});

await Component.odo.createComponentFromGit(application, componentTypeName, componentTypeVersion, componentName, repoURI, folder[0], gitRef.label);
await Component.odo.createComponentFromGit(application, componentTypeName, componentTypeVersion, componentName, repoURI, workspacePath, gitRef.label);
return `Component '${componentName}' successfully created`;
}

static async createFromBinary(context: OpenShiftObject): Promise<string> {

let application: OpenShiftObject = context;
let folder: WorkspaceFolderItem[] = [];

if (!application) application = await Component.getOpenshiftData(context);

if (!application) return null;
if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) {
folder = workspace.workspaceFolders.filter(
(value) => {
let result = true;
try {
result = !fs.statSync(path.join(value.uri.fsPath, '.odo', 'config.yaml')).isFile();
} catch (ignore) {
}
return result;
}
).map(
(folder) => ({ label: `$(file-directory) ${folder.uri.fsPath}`, uri: folder.uri })
);
}
const addWorkspaceFolder = new CreateWorkspaceItem();
const choice: any = await window.showQuickPick([addWorkspaceFolder, ...folder], {placeHolder: "Select context folder"});

if (!choice) return null;
let workspacePath: Uri;

if (choice.label === addWorkspaceFolder.label) {
const folders = await window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
defaultUri: Uri.file(Platform.getUserHomePath()),
openLabel: "Add context Folder for Component"
});
if (!folders) return null;
workspacePath = folders[0];
} else {
workspacePath = choice.uri;
}
const workspacePath = await selectWorkspaceFolder();

if (!workspacePath) return null;

const globPath = process.platform === 'win32' ? workspacePath.fsPath.replace(/\\/g, '/') : workspacePath.path;
const paths = globby.sync(`${globPath}/*.+(jar|war)`, { extglob: true });

Expand Down
22 changes: 16 additions & 6 deletions src/util/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class CreateWorkspaceItem implements QuickPickItem {

constructor() { }

get label(): string { return `$(plus) Add new workspace folder.`; }
get description(): string { return 'Folder which does not have an openshift context'; }
get label(): string { return `$(plus) Add new context folder.`; }
get description(): string { return 'Folder which does not have an OpenShift context'; }

}

Expand All @@ -33,7 +33,8 @@ export async function selectWorkspaceFolder(): Promise<Uri> {
);
}
const addWorkspaceFolder = new CreateWorkspaceItem();
const choice: any = await window.showQuickPick([addWorkspaceFolder, ...folder], {placeHolder: "Select workspace folder"});
const choice: any = await window.showQuickPick([addWorkspaceFolder, ...folder], {placeHolder: "Select context folder"});
if (!choice) return null;

let workspacePath: Uri;

Expand All @@ -43,12 +44,21 @@ export async function selectWorkspaceFolder(): Promise<Uri> {
canSelectFolders: true,
canSelectMany: false,
defaultUri: Uri.file(Platform.getUserHomePath()),
openLabel: "Add workspace Folder for Component"
openLabel: "Add context folder for component in workspace."
});
if (!folders) return null;
workspacePath = folders[0];
if (await checkComponentFolder(folders[0])) {
window.showInformationMessage('The folder selected already contains a component. Please select a different folder.');
return this.selectWorkspaceFolder();
} else {
workspacePath = folders[0];
}
} else if (choice) {
workspacePath = choice.uri;
}
return workspacePath;
}
}

async function checkComponentFolder(folder: Uri) {
return fs.existsSync(path.join(folder.fsPath, '.odo', 'config.yaml'));
}

0 comments on commit 79e3a49

Please sign in to comment.