Skip to content
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
32 changes: 13 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"@redhat-developer/vscode-redhat-telemetry": "^0.5.2",
"clsx": "^1.1.1",
"fs-extra": "^10.0.0",
"git-url-parse": "^13.1.0",
"globby": "^10.0.1",
"got": "^11.8.6",
"hasha": "^5.2.2",
Expand Down Expand Up @@ -152,6 +151,7 @@
"eslint-plugin-prettier": "^4.0.0",
"express": "^4.17.2",
"file-loader": "^6.2.0",
"git-up": "^7.0.0",
"glob": "^7.2.0",
"istanbul": "^0.4.5",
"leasot": "^12.0.0",
Expand Down
16 changes: 13 additions & 3 deletions src/webview/git-import/app/gitImport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { VSCodeMessage } from './vsCodeMessage';
import { CardItem } from './cardItem';
import { ComponentTypeDescription } from '../../../odo/componentType';
import { LoadScreen } from './loading';
import { gitUrlParse } from '../gitParse';
import './gitImport.scss';
import { Uri } from 'vscode';

Expand Down Expand Up @@ -135,7 +136,7 @@ export class GitImport extends React.Component<DefaultProps, {
this.setState({ showLoadScreen: false, notification: '' });
this.setState({
gitURL: {
value: message.data.gitURL,
value: this.getTrimmedURL(message.data.gitURL),
showError: message.data.error,
helpText: message.data.helpText,
parser: message.data.parser
Expand Down Expand Up @@ -193,7 +194,9 @@ export class GitImport extends React.Component<DefaultProps, {
});
} else if (message.data.action === 'cloneStarted') {
this.setState({ showLoadScreen: true, notification: 'Cloning the repository' });
} else if (message.data.action === 'cloneCompleted') {
} else if (message.data.action === 'cloneError') {
this.setState({ showLoadScreen: false, notification: message.data.error });
} else if (message.data.action === 'cloneCompleted') {
this.setState({ showLoadScreen: true, notification: 'Scanning through git repo and recommending the import strategy...' });
VSCodeMessage.postMessage({
action: 'parseGitURL',
Expand All @@ -206,6 +209,8 @@ export class GitImport extends React.Component<DefaultProps, {
this.setState({ showLoadScreen: false, notification: '' });
} else if (message.data.action === 'devfileRegenerated') {
this.setState({ showLoadScreen: true, notification: 'Scanning through git repo and recommending the import strategy...' });
} else if (message.data.action === 'close') {
this.initalize(true);
}
});
}
Expand Down Expand Up @@ -236,6 +241,11 @@ export class GitImport extends React.Component<DefaultProps, {
});
}

getTrimmedURL = (value: string): string => {
Comment thread
msivasubramaniaan marked this conversation as resolved.
const parsedURL = gitUrlParse(value);
return gitUrlParse.stringify(parsedURL, '');
}

analyze = (): void => {
this.setState({
applicationName: undefined,
Expand All @@ -251,7 +261,7 @@ export class GitImport extends React.Component<DefaultProps, {
this.setState({ showLoadScreen: true, notification: 'Validating the repo URL...' });
VSCodeMessage.postMessage({
action: 'validateGitURL',
param: this.state.gitURL.value
param: this.getTrimmedURL(this.state.gitURL.value)
});
}

Expand Down
40 changes: 21 additions & 19 deletions src/webview/git-import/gitImportLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { selectWorkspaceFolder } from '../../util/workspace';
import { vsCommand } from '../../vscommand';
import { loadWebviewHtml } from '../common-ext/utils';
import { DevfileConverter } from './devfileConverter';
import GitUrlParse = require('git-url-parse');
import { gitUrlParse } from './gitParse';
Comment thread
msivasubramaniaan marked this conversation as resolved.
import treeKill = require('tree-kill')
import cp = require('child_process');
let panel: vscode.WebviewPanel;
Expand All @@ -28,7 +28,7 @@ let forceCancel = false;

interface CloneProcess {
status: boolean,
error: string
error: string | undefined
}

export class Command {
Expand Down Expand Up @@ -134,12 +134,13 @@ async function gitImportMessageListener(event: any): Promise<any> {
const selctedFolder: vscode.Uri = event.folder;
const cloneProcess: CloneProcess = await clone(event.gitURL, selctedFolder.fsPath);
if (!cloneProcess.status && cloneProcess.error) {
showError(event, event.folder.fsPath, cloneProcess.error);
showError(event.folder.fsPath, cloneProcess.error);
return null;
} else {
panel?.webview.postMessage({
action: 'cloneCompleted'
});
}
panel?.webview.postMessage({
action: 'cloneCompleted'
});
}
default:
break;
Expand Down Expand Up @@ -249,7 +250,7 @@ async function parseGitURL(event: any) {
name: event.projectName + '-comp',
error: compDescriptions.length > 0 ? false : true,
isDevFile: isDevFile,
helpText: compDescriptions.length > 0 ? 'The git repo is valid.' : 'Issue on Parsing Git URL/devfile',
helpText: compDescriptions.length > 0 ? 'The git repo URL is valid.' : 'Issue on Parsing Git URL/devfile',
compDescription: compDescriptions,
parser: event.parser
});
Expand All @@ -273,7 +274,7 @@ function validateGitURL(event: any) {
});
} else {
try {
const parse = GitUrlParse(event.param);
const parse = gitUrlParse(event.param);
Comment thread
msivasubramaniaan marked this conversation as resolved.
const isGitRepo = isGitURL(parse.host);
if (!isGitRepo) {
throw 'Invalid Git URL';
Expand All @@ -282,7 +283,7 @@ function validateGitURL(event: any) {
panel?.webview.postMessage({
action: event.action,
error: false,
helpText: 'The git repo is valid.',
helpText: 'The git repo URL is valid.',
parser: parse,
gitURL: event.param
});
Expand Down Expand Up @@ -319,8 +320,11 @@ function clone(url: string, location: string): Promise<CloneProcess> {
const gitExtension = vscode.extensions.getExtension('vscode.git').exports;
const git = gitExtension.getAPI(1).git.path;
// run 'git clone url location' as external process and return location
return new Promise((resolve, reject) => (childProcess = cp.exec(`${git} clone ${url} ${location}`, (error: cp.ExecException) => error ?
reject({ status: false, error: error.message }) : resolve({ status: true, error: undefined }))));
return new Promise((resolve, reject) => (childProcess = cp.exec(`${git} clone ${url} ${location}`,
(error: cp.ExecException) => {
error ? resolve({ status: false, error: error.message }) : resolve({ status: true, error: undefined });
}
)));
}

function validateComponentName(event: any) {
Expand Down Expand Up @@ -352,17 +356,15 @@ function validateDevFilePath(event: any) {
});
}

function showError(event: any, location: string, message: string): void {
function showError(location: string, message: string): void {
const permissonDeniedIndex = message.toLowerCase().indexOf('permission denied');
const errorMsg = permissonDeniedIndex !== -1 ? message.substring(permissonDeniedIndex) : 'Error occurred while cloning the repository. Please try again.';
panel?.webview.postMessage({
action: event.action,
status: false
action: 'cloneError',
error: errorMsg
});
if (!forceCancel) {
if (message.indexOf('already exists') !== -1) {
Comment thread
msivasubramaniaan marked this conversation as resolved.
vscode.window.showErrorMessage(`Folder already exists on the selected ${location.substring(0, location.lastIndexOf('\\'))}`);
} else {
vscode.window.showErrorMessage('Error occurred while cloning the repository. Please try again.');
}
vscode.window.showErrorMessage(errorMsg);
}
}

Expand Down
Loading