Skip to content

Commit a338442

Browse files
committed
Log the output of the git-clone command into the OpenShift Logs.
- Convert 'exec' call to use 'spawn' - Improve progress reporting when cloning git repo for component creation Signed-off-by: Roland Grunberg <[email protected]>
1 parent d4b0fae commit a338442

File tree

3 files changed

+51
-19
lines changed

3 files changed

+51
-19
lines changed

src/util/childProcessUtil.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import * as vscode from 'vscode';
88
import { Util as cp } from '../util/utils';
99
import { Filters } from './filters';
1010

11+
const channel = vscode.window.createOutputChannel('OpenShift');
12+
13+
export function getOpenShiftLogChannel(): vscode.OutputChannel {
14+
return channel;
15+
}
16+
1117
export interface CliExitData {
1218
readonly error: ExecException;
1319
readonly stdout: string;
@@ -38,32 +44,29 @@ class OdoChannel {
3844

3945
private static instance = new OdoChannel();
4046

41-
private channel: vscode.OutputChannel;
42-
4347
public static get Instance() {
4448
return OdoChannel.instance;
4549
}
4650

4751
public constructor() {
48-
this.channel = vscode.window.createOutputChannel('OpenShift');
4952
}
5053

5154
show(): void {
52-
this.channel.show();
55+
channel.show();
5356
}
5457

5558
print(text: string): void {
5659
const textData = OdoChannel.prettifyJson(text);
57-
this.channel.append(textData);
60+
channel.append(textData);
5861
if (!textData.endsWith('\n')) {
59-
this.channel.append('\n');
62+
channel.append('\n');
6063
}
6164
if (
6265
vscode.workspace
6366
.getConfiguration('openshiftToolkit')
6467
.get<boolean>('showChannelOnOutput')
6568
) {
66-
this.channel.show();
69+
channel.show();
6770
}
6871
}
6972

src/webview/create-component/createComponentLoader.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
} from '../common-ext/createComponentHelpers';
3838
import { loadWebviewHtml, validateGitURL } from '../common-ext/utils';
3939
import { Devfile, TemplateProjectIdentifier } from '../common/devfile';
40+
import { getOpenShiftLogChannel } from '../../util/childProcessUtil';
4041

4142
interface CloneProcess {
4243
status: boolean;
@@ -680,21 +681,38 @@ async function isDevfileExists(uri: vscode.Uri): Promise<boolean> {
680681
function clone(url: string, location: string, branch?: string): Promise<CloneProcess> {
681682
const gitExtension = vscode.extensions.getExtension('vscode.git').exports;
682683
const git = gitExtension.getAPI(1).git.path;
683-
let command = `${git} clone ${url} ${location}`;
684+
let command = `${git} clone --progress ${url} ${location}`;
684685
command = branch ? `${command} --branch ${branch}` : command;
685686
void CreateComponentLoader.panel.webview.postMessage({
686687
action: 'cloneExecution'
687688
});
688-
// run 'git clone url location' as external process and return location
689-
return new Promise((resolve, reject) =>
690-
cp.exec(command, (error: cp.ExecException) => {
691-
if (error) {
692-
resolve({ status: false, error: error.message });
693-
} else {
694-
resolve({ status: true, error: undefined });
695-
}
696-
})
697-
);
689+
const channel = getOpenShiftLogChannel();
690+
691+
return new Promise((resolve, reject) => {
692+
const proc = cp.spawn(command, {shell: true});
693+
channel.appendLine(command);
694+
695+
proc.stdout.on('data', (data) => {
696+
channel.append(data.toString());
697+
});
698+
proc.stderr.on('data', (data) => {
699+
channel.append(data.toString());
700+
701+
void CreateComponentLoader.panel.webview.postMessage({
702+
action: 'cloneProgress',
703+
data: {
704+
completionProgress: data.toString(),
705+
}
706+
});
707+
});
708+
709+
proc.on('error', (error) => {
710+
resolve({ status: false, error: error.message });
711+
});
712+
proc.on('close', (code) => {
713+
resolve({ status: true, error: undefined });
714+
});
715+
});
698716
}
699717

700718
async function validateFolderPath(path: string) {
@@ -715,4 +733,4 @@ async function validateFolderPath(path: string) {
715733
},
716734
});
717735
}
718-
}
736+
}

src/webview/create-component/pages/fromExistingGitRepo.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type RecommendedDevfileState = {
3636
completionValue: number;
3737
isDevfileExistsInRepo: boolean;
3838
noRecommendation: boolean;
39+
completionProgress: string;
3940
};
4041

4142
type GitURLState = {
@@ -63,6 +64,7 @@ export function FromExistingGitRepo({ setCurrentView }) {
6364
completionValue: 0,
6465
isDevfileExistsInRepo: false,
6566
noRecommendation: false,
67+
completionProgress: undefined
6668
});
6769
const [selectedDevfile, setSelectedDevfile] = React.useState<DevfileData>(undefined);
6870
const [initialComponentParentFolder, setInitialComponentParentFolder] = React.useState<string>(undefined);
@@ -123,6 +125,10 @@ export function FromExistingGitRepo({ setCurrentView }) {
123125
setRecommendedDevfile((prevState) => ({ ...prevState, completionValue: prevState.completionValue + 10}));
124126
break;
125127
}
128+
case 'cloneProgress': {
129+
setRecommendedDevfile((prevState) => ({ ...prevState, completionProgress: message.data.completionProgress}));
130+
break;
131+
}
126132
case 'getRecommendedDevfile': {
127133
setRecommendedDevfile((prevState) => ({ ...prevState, completionValue: prevState.completionValue + 45}));
128134
break;
@@ -299,6 +305,11 @@ export function FromExistingGitRepo({ setCurrentView }) {
299305
Cloning git repository and scanning for
300306
recommended devfile.
301307
</Typography>
308+
{recommendedDevfile.completionProgress && (
309+
<Typography variant="body2">
310+
{recommendedDevfile.completionProgress}
311+
</Typography>
312+
)}
302313
</Stack>
303314
)}
304315
</>

0 commit comments

Comments
 (0)