Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
feat: don't add merge-contribution attribute into the dev container (#…
Browse files Browse the repository at this point in the history
…755)

* feat: don't add merge contribution attribute into dev container

---------

Signed-off-by: Valeriy Svydenko <[email protected]>
  • Loading branch information
svor authored Jun 30, 2023
1 parent d5a7266 commit ea73e8b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 34 deletions.
22 changes: 2 additions & 20 deletions tools/devworkspace-generator/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
V1alpha2DevWorkspace,
V1alpha2DevWorkspaceMetadata,
V1alpha2DevWorkspaceSpecContributions,
V1alpha2DevWorkspaceSpecTemplateComponents,
V1alpha2DevWorkspaceTemplate,
V1alpha2DevWorkspaceTemplateSpec,
} from '@devfile/api';
Expand All @@ -32,8 +31,6 @@ type DevfileLike = V221Devfile & {

@injectable()
export class Generate {
static readonly MERGE_CONTRIBUTION = 'controller.devfile.io/merge-contribution';

@inject(DevContainerComponentFinder)
private devContainerComponentFinder: DevContainerComponentFinder;

Expand Down Expand Up @@ -127,23 +124,8 @@ export class Generate {
suffix,
};

// grab container where to inject controller.devfile.io/merge-contribution attribute
let devContainer: V1alpha2DevWorkspaceSpecTemplateComponents | undefined =
await this.devContainerComponentFinder.find(context, injectDefaultComponent, defaultComponentImage);

if (!devContainer) {
return context;
}

// add attributes
let devContainerAttributes = devContainer.attributes;
if (!devContainerAttributes) {
devContainerAttributes = {};
devContainerAttributes[Generate.MERGE_CONTRIBUTION] = true;
devContainer.attributes = devContainerAttributes;
} else {
devContainerAttributes[Generate.MERGE_CONTRIBUTION] = true;
}
// find devContainer component, add a default one if not found
await this.devContainerComponentFinder.find(context, injectDefaultComponent, defaultComponentImage);

return context;
}
Expand Down
18 changes: 4 additions & 14 deletions tools/devworkspace-generator/tests/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ metadata:
// expect not to write the file
expect(fsWriteFileSpy).not.toBeCalled();
expect(JSON.stringify(context.devfile)).toEqual(
'{"schemaVersion":"2.2.0","metadata":{"name":"my-dummy-project"},"components":[{"name":"dev-container","mountSources":true,"container":{"image":"quay.io/foo/bar"},"attributes":{"controller.devfile.io/merge-contribution":true}}]}'
'{"schemaVersion":"2.2.0","metadata":{"name":"my-dummy-project"},"components":[{"name":"dev-container","mountSources":true,"container":{"image":"quay.io/foo/bar"}}]}'
);
const expectedDevWorkspace = {
apiVersion: 'workspace.devfile.io/v1alpha2',
Expand All @@ -141,9 +141,6 @@ metadata:
container: {
image: 'quay.io/foo/bar',
},
attributes: {
'controller.devfile.io/merge-contribution': true,
},
},
],
},
Expand Down Expand Up @@ -189,7 +186,7 @@ metadata:
// expect not to write the file
expect(fsWriteFileSpy).not.toBeCalled();
expect(JSON.stringify(context.devfile)).toEqual(
'{"schemaVersion":"2.2.0","metadata":{"generateName":"custom-project"},"components":[{"name":"dev-container","mountSources":true,"container":{"image":"quay.io/foo/bar"},"attributes":{"controller.devfile.io/merge-contribution":true}}]}'
'{"schemaVersion":"2.2.0","metadata":{"generateName":"custom-project"},"components":[{"name":"dev-container","mountSources":true,"container":{"image":"quay.io/foo/bar"}}]}'
);
const expectedDevWorkspace = {
apiVersion: 'workspace.devfile.io/v1alpha2',
Expand All @@ -211,9 +208,6 @@ metadata:
container: {
image: 'quay.io/foo/bar',
},
attributes: {
'controller.devfile.io/merge-contribution': true,
},
},
],
},
Expand Down Expand Up @@ -260,7 +254,7 @@ metadata:
// expect to write the file
expect(fsWriteFileSpy).toBeCalled();
expect(JSON.stringify(context.devfile)).toEqual(
'{"schemaVersion":"2.2.0","metadata":{"name":"my-dummy-project"},"components":[{"name":"dev-container","mountSources":true,"container":{"image":"quay.io/foo/bar"},"attributes":{"controller.devfile.io/merge-contribution":true}}]}'
'{"schemaVersion":"2.2.0","metadata":{"name":"my-dummy-project"},"components":[{"name":"dev-container","mountSources":true,"container":{"image":"quay.io/foo/bar"}}]}'
);
const expectedDevWorkspace = {
apiVersion: 'workspace.devfile.io/v1alpha2',
Expand All @@ -282,9 +276,6 @@ metadata:
container: {
image: 'quay.io/foo/bar',
},
attributes: {
'controller.devfile.io/merge-contribution': true,
},
},
],
},
Expand Down Expand Up @@ -331,7 +322,7 @@ metadata:
// expect to write the file
expect(fsWriteFileSpy).toBeCalled();
expect(JSON.stringify(context.devfile)).toEqual(
'{"schemaVersion":"2.2.0","metadata":{"name":"my-dummy-project"},"components":[{"name":"dev-container","attributes":{"old":"attribute","controller.devfile.io/merge-contribution":true},"mountSources":true,"container":{"image":"quay.io/foo/bar"}}]}'
'{"schemaVersion":"2.2.0","metadata":{"name":"my-dummy-project"},"components":[{"name":"dev-container","attributes":{"old":"attribute"},"mountSources":true,"container":{"image":"quay.io/foo/bar"}}]}'
);
const expectedDevWorkspace = {
apiVersion: 'workspace.devfile.io/v1alpha2',
Expand All @@ -351,7 +342,6 @@ metadata:
name: 'dev-container',
attributes: {
old: 'attribute',
'controller.devfile.io/merge-contribution': true,
},
mountSources: true,
container: {
Expand Down

0 comments on commit ea73e8b

Please sign in to comment.