Skip to content

Commit 5527e7a

Browse files
trim the git URL till repo name (#2991)
* trim the git url till repo name Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * replaced to js file Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * trimmed url once user clicked analyze button Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * added git_suffix check on the parser Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * revert Signed-off-by: msivasubramaniaan <msivasub@redhat.com> --------- Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
1 parent 78d0933 commit 5527e7a

File tree

5 files changed

+364
-42
lines changed

5 files changed

+364
-42
lines changed

package-lock.json

Lines changed: 13 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
"@redhat-developer/vscode-redhat-telemetry": "^0.5.2",
7979
"clsx": "^1.1.1",
8080
"fs-extra": "^10.0.0",
81-
"git-url-parse": "^13.1.0",
8281
"globby": "^10.0.1",
8382
"got": "^11.8.6",
8483
"hasha": "^5.2.2",
@@ -152,6 +151,7 @@
152151
"eslint-plugin-prettier": "^4.0.0",
153152
"express": "^4.17.2",
154153
"file-loader": "^6.2.0",
154+
"git-up": "^7.0.0",
155155
"glob": "^7.2.0",
156156
"istanbul": "^0.4.5",
157157
"leasot": "^12.0.0",

src/webview/git-import/app/gitImport.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { VSCodeMessage } from './vsCodeMessage';
1616
import { CardItem } from './cardItem';
1717
import { ComponentTypeDescription } from '../../../odo/componentType';
1818
import { LoadScreen } from './loading';
19+
import { gitUrlParse } from '../gitParse';
1920
import './gitImport.scss';
2021
import { Uri } from 'vscode';
2122

@@ -135,7 +136,7 @@ export class GitImport extends React.Component<DefaultProps, {
135136
this.setState({ showLoadScreen: false, notification: '' });
136137
this.setState({
137138
gitURL: {
138-
value: message.data.gitURL,
139+
value: this.getTrimmedURL(message.data.gitURL),
139140
showError: message.data.error,
140141
helpText: message.data.helpText,
141142
parser: message.data.parser
@@ -193,7 +194,9 @@ export class GitImport extends React.Component<DefaultProps, {
193194
});
194195
} else if (message.data.action === 'cloneStarted') {
195196
this.setState({ showLoadScreen: true, notification: 'Cloning the repository' });
196-
} else if (message.data.action === 'cloneCompleted') {
197+
} else if (message.data.action === 'cloneError') {
198+
this.setState({ showLoadScreen: false, notification: message.data.error });
199+
} else if (message.data.action === 'cloneCompleted') {
197200
this.setState({ showLoadScreen: true, notification: 'Scanning through git repo and recommending the import strategy...' });
198201
VSCodeMessage.postMessage({
199202
action: 'parseGitURL',
@@ -206,6 +209,8 @@ export class GitImport extends React.Component<DefaultProps, {
206209
this.setState({ showLoadScreen: false, notification: '' });
207210
} else if (message.data.action === 'devfileRegenerated') {
208211
this.setState({ showLoadScreen: true, notification: 'Scanning through git repo and recommending the import strategy...' });
212+
} else if (message.data.action === 'close') {
213+
this.initalize(true);
209214
}
210215
});
211216
}
@@ -236,6 +241,11 @@ export class GitImport extends React.Component<DefaultProps, {
236241
});
237242
}
238243

244+
getTrimmedURL = (value: string): string => {
245+
const parsedURL = gitUrlParse(value);
246+
return gitUrlParse.stringify(parsedURL, '');
247+
}
248+
239249
analyze = (): void => {
240250
this.setState({
241251
applicationName: undefined,
@@ -251,7 +261,7 @@ export class GitImport extends React.Component<DefaultProps, {
251261
this.setState({ showLoadScreen: true, notification: 'Validating the repo URL...' });
252262
VSCodeMessage.postMessage({
253263
action: 'validateGitURL',
254-
param: this.state.gitURL.value
264+
param: this.getTrimmedURL(this.state.gitURL.value)
255265
});
256266
}
257267

src/webview/git-import/gitImportLoader.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { selectWorkspaceFolder } from '../../util/workspace';
1919
import { vsCommand } from '../../vscommand';
2020
import { loadWebviewHtml } from '../common-ext/utils';
2121
import { DevfileConverter } from './devfileConverter';
22-
import GitUrlParse = require('git-url-parse');
22+
import { gitUrlParse } from './gitParse';
2323
import treeKill = require('tree-kill')
2424
import cp = require('child_process');
2525
let panel: vscode.WebviewPanel;
@@ -28,7 +28,7 @@ let forceCancel = false;
2828

2929
interface CloneProcess {
3030
status: boolean,
31-
error: string
31+
error: string | undefined
3232
}
3333

3434
export class Command {
@@ -134,12 +134,13 @@ async function gitImportMessageListener(event: any): Promise<any> {
134134
const selctedFolder: vscode.Uri = event.folder;
135135
const cloneProcess: CloneProcess = await clone(event.gitURL, selctedFolder.fsPath);
136136
if (!cloneProcess.status && cloneProcess.error) {
137-
showError(event, event.folder.fsPath, cloneProcess.error);
137+
showError(event.folder.fsPath, cloneProcess.error);
138138
return null;
139+
} else {
140+
panel?.webview.postMessage({
141+
action: 'cloneCompleted'
142+
});
139143
}
140-
panel?.webview.postMessage({
141-
action: 'cloneCompleted'
142-
});
143144
}
144145
default:
145146
break;
@@ -249,7 +250,7 @@ async function parseGitURL(event: any) {
249250
name: event.projectName + '-comp',
250251
error: compDescriptions.length > 0 ? false : true,
251252
isDevFile: isDevFile,
252-
helpText: compDescriptions.length > 0 ? 'The git repo is valid.' : 'Issue on Parsing Git URL/devfile',
253+
helpText: compDescriptions.length > 0 ? 'The git repo URL is valid.' : 'Issue on Parsing Git URL/devfile',
253254
compDescription: compDescriptions,
254255
parser: event.parser
255256
});
@@ -273,7 +274,7 @@ function validateGitURL(event: any) {
273274
});
274275
} else {
275276
try {
276-
const parse = GitUrlParse(event.param);
277+
const parse = gitUrlParse(event.param);
277278
const isGitRepo = isGitURL(parse.host);
278279
if (!isGitRepo) {
279280
throw 'Invalid Git URL';
@@ -282,7 +283,7 @@ function validateGitURL(event: any) {
282283
panel?.webview.postMessage({
283284
action: event.action,
284285
error: false,
285-
helpText: 'The git repo is valid.',
286+
helpText: 'The git repo URL is valid.',
286287
parser: parse,
287288
gitURL: event.param
288289
});
@@ -319,8 +320,11 @@ function clone(url: string, location: string): Promise<CloneProcess> {
319320
const gitExtension = vscode.extensions.getExtension('vscode.git').exports;
320321
const git = gitExtension.getAPI(1).git.path;
321322
// run 'git clone url location' as external process and return location
322-
return new Promise((resolve, reject) => (childProcess = cp.exec(`${git} clone ${url} ${location}`, (error: cp.ExecException) => error ?
323-
reject({ status: false, error: error.message }) : resolve({ status: true, error: undefined }))));
323+
return new Promise((resolve, reject) => (childProcess = cp.exec(`${git} clone ${url} ${location}`,
324+
(error: cp.ExecException) => {
325+
error ? resolve({ status: false, error: error.message }) : resolve({ status: true, error: undefined });
326+
}
327+
)));
324328
}
325329

326330
function validateComponentName(event: any) {
@@ -352,17 +356,15 @@ function validateDevFilePath(event: any) {
352356
});
353357
}
354358

355-
function showError(event: any, location: string, message: string): void {
359+
function showError(location: string, message: string): void {
360+
const permissonDeniedIndex = message.toLowerCase().indexOf('permission denied');
361+
const errorMsg = permissonDeniedIndex !== -1 ? message.substring(permissonDeniedIndex) : 'Error occurred while cloning the repository. Please try again.';
356362
panel?.webview.postMessage({
357-
action: event.action,
358-
status: false
363+
action: 'cloneError',
364+
error: errorMsg
359365
});
360366
if (!forceCancel) {
361-
if (message.indexOf('already exists') !== -1) {
362-
vscode.window.showErrorMessage(`Folder already exists on the selected ${location.substring(0, location.lastIndexOf('\\'))}`);
363-
} else {
364-
vscode.window.showErrorMessage('Error occurred while cloning the repository. Please try again.');
365-
}
367+
vscode.window.showErrorMessage(errorMsg);
366368
}
367369
}
368370

0 commit comments

Comments
 (0)