Skip to content

Commit d7f396f

Browse files
committed
fixup! Start workspace from default devfile on private repository SSH url
1 parent c57701e commit d7f396f

File tree

4 files changed

+18
-152
lines changed

4 files changed

+18
-152
lines changed

packages/dashboard-frontend/src/components/WorkspaceProgress/CreatingSteps/Apply/Devfile/__tests__/index.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ describe('Creating steps, applying a devfile', () => {
238238
expect(prepareDevfile).toHaveBeenCalledWith(
239239
expect.objectContaining({
240240
attributes: {
241+
'controller.devfile.io/bootstrap-devworkspace': true,
241242
defaultDevfile: true,
242243
},
243244
}),

packages/dashboard-frontend/src/components/WorkspaceProgress/CreatingSteps/Apply/Devfile/index.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,12 @@ class CreatingStepApplyDevfile extends ProgressStep<Props, State> {
181181

182182
// when using the default devfile instead of a user devfile
183183
if (factoryResolver === undefined && isEqual(devfile, defaultDevfile)) {
184-
if (FactoryLocationAdapter.isSshLocation(factoryParams.sourceUrl)) {
185-
if (!devfile.attributes) {
186-
devfile.attributes = {};
187-
}
188-
189-
devfile.attributes['controller.devfile.io/bootstrap-devworkspace'] = true;
184+
if (!devfile.attributes) {
185+
devfile.attributes = {};
190186
}
191187

188+
devfile.attributes['controller.devfile.io/bootstrap-devworkspace'] = true;
189+
192190
if (devfile.projects === undefined) {
193191
devfile.projects = [];
194192
}
@@ -203,13 +201,11 @@ class CreatingStepApplyDevfile extends ProgressStep<Props, State> {
203201
}
204202
}
205203
} else if (factoryResolver?.source === 'repo') {
206-
if (FactoryLocationAdapter.isSshLocation(factoryParams.sourceUrl)) {
207-
if (!devfile.attributes) {
208-
devfile.attributes = {};
209-
}
210-
211-
devfile.attributes['controller.devfile.io/bootstrap-devworkspace'] = true;
204+
if (!devfile.attributes) {
205+
devfile.attributes = {};
212206
}
207+
208+
devfile.attributes['controller.devfile.io/bootstrap-devworkspace'] = true;
213209
}
214210

215211
if (remotes) {

packages/dashboard-frontend/src/components/WorkspaceProgress/CreatingSteps/Fetch/Devfile/__tests__/index.spec.tsx

Lines changed: 5 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { AlertItem } from '@/services/helpers/types';
3535
import { AppThunk } from '@/store';
3636
import { MockStoreBuilder } from '@/store/__mocks__/mockStore';
3737
import { factoryResolverActionCreators, OAuthResponse } from '@/store/FactoryResolver';
38+
import { prepareDevfile } from '@/components/WorkspaceProgress/CreatingSteps/Apply/Devfile/prepareDevfile';
3839

3940
jest.mock('@/components/WorkspaceProgress/TimeLimit');
4041

@@ -345,7 +346,7 @@ describe('Creating steps, fetching a devfile', () => {
345346
});
346347
});
347348

348-
describe('unsupported git provider error', () => {
349+
describe('unsupported git provider', () => {
349350
let emptyStore: Store;
350351
const rejectReason = 'Failed to fetch devfile';
351352

@@ -354,110 +355,13 @@ describe('Creating steps, fetching a devfile', () => {
354355
mockRequestFactoryResolver.mockRejectedValueOnce(rejectReason);
355356
});
356357

357-
test('alert title', async () => {
358+
test('should continue with the default devfile', async () => {
358359
renderComponent(emptyStore, searchParams);
359360

360361
await jest.advanceTimersByTimeAsync(MIN_STEP_DURATION_MS);
361362

362-
const expectAlertItem = expect.objectContaining({
363-
title: 'Warning',
364-
actionCallbacks: [
365-
expect.objectContaining({
366-
title: 'Continue with default devfile',
367-
callback: expect.any(Function),
368-
}),
369-
expect.objectContaining({
370-
title: 'Reload',
371-
callback: expect.any(Function),
372-
}),
373-
],
374-
});
375-
await waitFor(() => expect(mockOnError).toHaveBeenCalledWith(expectAlertItem));
376-
377-
expect(mockOnNextStep).not.toHaveBeenCalled();
378-
});
379-
380-
test('action "Continue with default devfile"', async () => {
381-
// this deferred object will help run the callback at the right time
382-
const deferred = getDefer();
383-
384-
const actionTitle = 'Continue with default devfile';
385-
mockOnError.mockImplementationOnce((alertItem: AlertItem) => {
386-
const action = alertItem.actionCallbacks?.find(_action =>
387-
_action.title.startsWith(actionTitle),
388-
);
389-
expect(action).toBeDefined();
390-
391-
if (action) {
392-
deferred.promise.then(action.callback);
393-
} else {
394-
throw new Error('Action not found');
395-
}
396-
});
397-
398-
renderComponent(emptyStore, searchParams);
399-
await jest.runAllTimersAsync();
400-
401-
await waitFor(() => expect(mockOnError).toHaveBeenCalled());
402-
expect(mockOnRestart).not.toHaveBeenCalled();
403-
expect(mockOnNextStep).not.toHaveBeenCalled();
404-
405-
mockOnError.mockClear();
406-
407-
/* test the action */
408-
await jest.runOnlyPendingTimersAsync();
409-
410-
// resolve deferred to trigger the callback
411-
deferred.resolve();
412-
413-
await waitFor(() => expect(mockOnNextStep).toHaveBeenCalled());
414-
expect(mockOnRestart).not.toHaveBeenCalled();
415-
expect(mockOnError).not.toHaveBeenCalled();
416-
});
417-
418-
test('action "Reload"', async () => {
419-
// this deferred object will help run the callback at the right time
420-
const deferred = getDefer();
421-
422-
const actionTitle = 'Reload';
423-
mockOnError.mockImplementationOnce(async (alertItem: AlertItem) => {
424-
const action = alertItem.actionCallbacks?.find(_action =>
425-
_action.title.startsWith(actionTitle),
426-
);
427-
expect(action).toBeDefined();
428-
429-
if (action) {
430-
deferred.promise.then(action.callback);
431-
} else {
432-
throw new Error('Action not found');
433-
}
434-
});
435-
436-
renderComponent(emptyStore, searchParams);
437-
await jest.runAllTimersAsync();
438-
439-
await waitFor(() => expect(mockOnError).toHaveBeenCalled());
440-
expect(mockOnRestart).not.toHaveBeenCalled();
441-
expect(mockOnNextStep).not.toHaveBeenCalled();
442-
443-
// first call resolves with error
444-
expect(mockRequestFactoryResolver).toHaveBeenCalledTimes(1);
445-
446-
mockOnError.mockClear();
447-
448-
/* test the action */
449-
450-
await jest.runAllTimersAsync();
451-
452-
// resolve deferred to trigger the callback
453-
deferred.resolve();
454-
455-
await waitFor(() => expect(mockOnRestart).toHaveBeenCalled());
456-
expect(mockOnNextStep).not.toHaveBeenCalled();
457-
expect(mockOnError).not.toHaveBeenCalled();
458-
459-
// should request the factory resolver for the second time
460-
await waitFor(() => expect(mockRequestFactoryResolver).toHaveBeenCalledTimes(2));
363+
await waitFor(() => expect(mockOnError).not.toHaveBeenCalled());
364+
expect(mockOnNextStep).toHaveBeenCalled();
461365
});
462366
});
463367

packages/dashboard-frontend/src/components/WorkspaceProgress/CreatingSteps/Fetch/Devfile/index.tsx

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ export class ApplyingDevfileError extends Error {
4646
}
4747
}
4848

49-
export class UnsupportedGitProviderError extends Error {
50-
constructor(message: string) {
51-
super(message);
52-
this.name = 'UnsupportedGitProviderError';
53-
}
54-
}
55-
5649
const RELOADS_LIMIT = 2;
5750
type ReloadsInfo = {
5851
[url: string]: number;
@@ -70,7 +63,6 @@ export type State = ProgressStepState & {
7063

7164
class CreatingStepFetchDevfile extends ProgressStep<Props, State> {
7265
protected readonly name = 'Inspecting repo';
73-
private readonly sshPattern = new RegExp('(git@|(ssh|git)://).*');
7466

7567
constructor(props: Props) {
7668
super(props);
@@ -220,15 +212,12 @@ class CreatingStepFetchDevfile extends ProgressStep<Props, State> {
220212
}
221213
if (
222214
errorMessage === 'Failed to fetch devfile' ||
215+
errorMessage ===
216+
'Cannot build factory with any of the provided parameters. Please check parameters correctness, and resend query.' ||
223217
errorMessage.startsWith('Could not reach devfile')
224218
) {
225-
// check if the source url is an SSH url
226-
if (this.sshPattern.test(sourceUrl)) {
227-
this.setState({ useDefaultDevfile: true });
228-
return true;
229-
} else {
230-
throw new UnsupportedGitProviderError(errorMessage);
231-
}
219+
this.setState({ useDefaultDevfile: true });
220+
return true;
232221
}
233222
throw e;
234223
}
@@ -349,30 +338,6 @@ class CreatingStepFetchDevfile extends ProgressStep<Props, State> {
349338
],
350339
};
351340
}
352-
if (error instanceof UnsupportedGitProviderError) {
353-
return {
354-
key,
355-
title: 'Warning',
356-
variant: AlertVariant.warning,
357-
children: (
358-
<ExpandableWarning
359-
textBefore="Could not find any devfile in the Git repository"
360-
errorMessage={helpers.errors.getMessage(error)}
361-
textAfter="The Git provider is not supported."
362-
/>
363-
),
364-
actionCallbacks: [
365-
{
366-
title: 'Continue with default devfile',
367-
callback: () => this.handleDefaultDevfile(key),
368-
},
369-
{
370-
title: 'Reload',
371-
callback: () => this.handleRestart(key),
372-
},
373-
],
374-
};
375-
}
376341
return {
377342
key,
378343
title: 'Failed to create the workspace',

0 commit comments

Comments
 (0)