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
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ describe('Server Config API Service', () => {

describe('Hide editors by name array', () => {
test('getting showDeprecated value', () => {
const res = serverConfigService.gеtHideEditorsById(buildCustomResource());
const res = serverConfigService.getHideEditorsById(buildCustomResource());
expect(res).toEqual([]);
});
test('getting hideByName value', () => {
process.env['CHE_HIDE_EDITORS_BY_ID'] =
'che-incubator/che-idea-server/latest, che-incubator/che-idea-server/next';
const res = serverConfigService.gеtHideEditorsById(buildCustomResource());
const res = serverConfigService.getHideEditorsById(buildCustomResource());
expect(res).toEqual([
'che-incubator/che-idea-server/latest',
'che-incubator/che-idea-server/next',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export class ServerConfigApiService implements IServerConfigApi {
return value === 'true';
}

gеtHideEditorsById(cheCustomResource: CheClusterCustomResource): string[] {
getHideEditorsById(cheCustomResource: CheClusterCustomResource): string[] {
const value = getEnvVarValue('CHE_HIDE_EDITORS_BY_ID', cheCustomResource);
if (!value) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export interface IServerConfigApi {
/**
* Returns the hideEditorsById value
*/
gеtHideEditorsById(cheCustomResource: CheClusterCustomResource): string[];
getHideEditorsById(cheCustomResource: CheClusterCustomResource): string[];

/**
* Returns the Machine (hardware) type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const getDevWorkspaceClient = jest.fn(
getAdvancedAuthorization: _cheCustomResource => stubAdvancedAuthorization,
getAllowedSourceUrls: _cheCustomResource => stubAllowedSourceUrls,
getShowDeprecatedEditors: _cheCustomResource => stubShowDeprecatedEditors,
gеtHideEditorsById: _cheCustomResource => stubHideEditorsById,
getHideEditorsById: _cheCustomResource => stubHideEditorsById,
} as IServerConfigApi,
devworkspaceApi: {
create: (_devworkspace, _namespace) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function registerServerConfigRoute(instance: FastifyInstance) {
const allowedSourceUrls = serverConfigApi.getAllowedSourceUrls(cheCustomResource);
const axiosRequestTimeout = serverConfigApi.getAxiosRequestTimeout();
const showDeprecated = serverConfigApi.getShowDeprecatedEditors(cheCustomResource);
const hideById = serverConfigApi.gеtHideEditorsById(cheCustomResource);
const hideById = serverConfigApi.getHideEditorsById(cheCustomResource);

const serverConfig: api.IServerConfig = {
containerBuild,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '@/components/WorkspaceProgress/CreatingSteps/Apply/Devfile/getGitRemotes';
import { buildFactoryLoaderPath } from '@/preload/main';
import { FactoryLocationAdapter } from '@/services/factory-location-adapter';
import { REVISION } from '@/services/helpers/factoryFlow/buildFactoryParams';
import { REVISION_ATTR } from '@/services/helpers/factoryFlow/buildFactoryParams';

const BR_NAME_REGEX = /^[0-9A-Za-z-./_]{1,256}$/;

Expand Down Expand Up @@ -317,7 +317,7 @@ export function getGitRepoOptionsFromLocation(location: string): {
console.log(`Unable to get branch from '${location}'.${common.helpers.errors.getMessage(e)}`);
}
} else if (!FactoryLocationAdapter.isHttpLocation(location)) {
gitBranch = searchParams.get(REVISION) || undefined;
gitBranch = searchParams.get(REVISION_ATTR) || undefined;
}
return { location, gitBranch, remotes, devfilePath, hasSupportedGitService };
}
Expand Down Expand Up @@ -440,7 +440,7 @@ export function setGitRepoOptionsToLocation(
state.gitBranch = newOptions.gitBranch;
}
if (!FactoryLocationAdapter.isHttpLocation(location) && newOptions.gitBranch) {
searchParams.set(REVISION, newOptions.gitBranch);
searchParams.set(REVISION_ATTR, newOptions.gitBranch);
}
// update the location with the new gitBranch value
let searchParamsStr = decodeURIComponent(searchParamsToString(searchParams));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import React from 'react';
import { connect, ConnectedProps } from 'react-redux';

import { AppAlerts } from '@/services/alerts/appAlerts';
import { getRepoFromLocation } from '@/services/helpers/factoryFlow/getRepoFromLocation';
import { RootState } from '@/store';
import { selectIsAllowedSourcesConfigured } from '@/store/ServerConfig/selectors';
import { workspacePreferencesActionCreators } from '@/store/Workspaces/Preferences';
Expand Down Expand Up @@ -163,7 +164,10 @@ class UntrustedSourceModal extends React.Component<Props, State> {
} else if (trustAllCheckbox) {
await this.props.addTrustedSource('*');
} else {
await this.props.addTrustedSource(location);
// Extract clean repository URL without branches and factory parameters
// This ensures we store only the base repo URL for comparison
const repoUrl = getRepoFromLocation(location);
await this.props.addTrustedSource(repoUrl);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,12 @@ describe('Creating steps, checking existing workspaces', () => {
annotations: {
[DEVWORKSPACE_DEVFILE_SOURCE]: dump({
factory: {
params: 'url=https://github.com/eclipse-che/che-dashboard',
params:
'url=https://github.com/eclipse-che/che-dashboard&revision=revision',
},
}),
},
})
.withSpec({
template: {
projects: [
{
git: {
remotes: {
origin: 'remote',
},
checkoutFrom: { revision: 'revision' },
},
name: 'project-1',
},
],
},
})
.build(),
new DevWorkspaceBuilder()
.withMetadata({
Expand Down Expand Up @@ -310,10 +296,11 @@ describe('Creating steps, checking existing workspaces', () => {
);
});

it('should not open the existing workspace created from the same repo with revision in workspace', async () => {
it('should not open workspace when factory params have revision but workspace does not', async () => {
searchParams.delete(DEV_WORKSPACE_ATTR);
searchParams.set(EXISTING_WORKSPACE_NAME, 'project-1');
searchParams.set(FACTORY_URL_ATTR, 'https://github.com/eclipse-che/che-dashboard');
searchParams.set(REVISION_ATTR, 'feature-branch');

const resources: DevWorkspaceResources = [
{
Expand All @@ -338,34 +325,6 @@ describe('Creating steps, checking existing workspaces', () => {
}),
},
})
.withSpec({
template: {
projects: [
{
git: {
remotes: {
origin: 'remote',
},
checkoutFrom: { revision: 'revision' },
},
name: 'project-1',
},
],
},
})
.build(),
new DevWorkspaceBuilder()
.withMetadata({
name: 'project-2',
namespace: 'user-che',
annotations: {
[DEVWORKSPACE_DEVFILE_SOURCE]: dump({
factory: {
params: 'url=https://github.com/eclipse-che/che-dashboard',
},
}),
},
})
.build(),
],
})
Expand Down Expand Up @@ -398,11 +357,11 @@ describe('Creating steps, checking existing workspaces', () => {
);
});

it('should not open the existing workspace created from the same repo with revision in parameters', async () => {
it('should not open workspace when workspace has revision but factory params do not', async () => {
searchParams.delete(DEV_WORKSPACE_ATTR);
searchParams.set(EXISTING_WORKSPACE_NAME, 'project-1');
searchParams.set(FACTORY_URL_ATTR, 'https://github.com/eclipse-che/che-dashboard');
searchParams.set(REVISION_ATTR, 'revision');
// No REVISION_ATTR set

const resources: DevWorkspaceResources = [
{
Expand All @@ -422,20 +381,7 @@ describe('Creating steps, checking existing workspaces', () => {
annotations: {
[DEVWORKSPACE_DEVFILE_SOURCE]: dump({
factory: {
params: 'url=https://github.com/eclipse-che/che-dashboard',
},
}),
},
})
.build(),
new DevWorkspaceBuilder()
.withMetadata({
name: 'project-2',
namespace: 'user-che',
annotations: {
[DEVWORKSPACE_DEVFILE_SOURCE]: dump({
factory: {
params: 'url=https://github.com/eclipse-che/che-dashboard',
params: 'url=https://github.com/eclipse-che/che-dashboard&revision=main',
},
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,7 @@ class CreatingStepCheckExistingWorkspaces extends ProgressStep<Props, State> {
workspaces: Workspace[],
factoryParams: FactoryParams,
): Workspace[] {
return workspaces.filter(workspace => {
let revision: string | undefined;
const projects = workspace.ref.spec.template.projects;
if (projects && projects.length > 0) {
const git = projects[0].git;
if (git && git.checkoutFrom && git.checkoutFrom.revision) {
if (git.checkoutFrom.revision) {
revision = git.checkoutFrom.revision;
}
}
}
return workspace.source === factoryParams.sourceUrl && revision === factoryParams.revision;
});
return workspaces.filter(workspace => workspace.source === factoryParams.source);
}

protected buildAlertItem(error: Error): AlertItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,71 @@ import {
EDITOR_ATTR,
EXISTING_WORKSPACE_NAME,
FACTORY_ID_IGNORE_ATTRS,
FACTORY_URL_ATTR,
POLICIES_CREATE_ATTR,
REVISION_ATTR,
STORAGE_TYPE_ATTR,
} from '@/services/helpers/factoryFlow/buildFactoryParams';

describe('buildFactoryParams', () => {
describe('source', () => {
it('should return base URL when no factory params', () => {
const searchParams = new URLSearchParams({
[FACTORY_URL_ATTR]: 'https://github.com/user/repo',
});

expect(buildFactoryParams(searchParams).source).toBe('https://github.com/user/repo');
});

it('should include revision in source', () => {
const searchParams = new URLSearchParams({
[FACTORY_URL_ATTR]: 'https://github.com/user/repo',
[REVISION_ATTR]: 'main',
});

expect(buildFactoryParams(searchParams).source).toBe(
'https://github.com/user/repo?revision=main',
);
});

it('should include multiple factory params sorted alphabetically', () => {
const searchParams = new URLSearchParams({
[FACTORY_URL_ATTR]: 'https://github.com/user/repo',
[STORAGE_TYPE_ATTR]: 'per-user',
[EDITOR_ATTR]: 'che-code',
[REVISION_ATTR]: 'feature',
});

const source = buildFactoryParams(searchParams).source;
expect(source).toContain('https://github.com/user/repo');
expect(source).toContain('che-editor=che-code');
expect(source).toContain('revision=feature');
expect(source).toContain('storageType=per-user');
});

it('should not include existing param in source', () => {
const searchParams = new URLSearchParams({
[FACTORY_URL_ATTR]: 'https://github.com/user/repo',
[EXISTING_WORKSPACE_NAME]: 'my-workspace',
[REVISION_ATTR]: 'main',
});

const source = buildFactoryParams(searchParams).source;
expect(source).not.toContain('existing=');
expect(source).toContain('revision=main');
});

it('should include policies.create in source', () => {
const searchParams = new URLSearchParams({
[FACTORY_URL_ATTR]: 'https://github.com/user/repo',
[POLICIES_CREATE_ATTR]: 'perclick',
});

const source = buildFactoryParams(searchParams).source;
expect(source).toContain('policies.create=perclick');
});
});

describe('getStorageType', () => {
it('should return undefined', () => {
const searchParams = new URLSearchParams({
Expand Down
Loading