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

feat: Add an ability to pass editor description as URL to the generator #722

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
7 changes: 6 additions & 1 deletion tools/devworkspace-generator/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ export class Generate {
const suffix = devfile.metadata.name || '';

// devfile of the editor
const editorDevfile = jsYaml.load(editorContent);
let editorDevfile = jsYaml.load(editorContent);

// support for the inline format of the devfile
if (editorDevfile.inline) {
editorDevfile = editorDevfile.inline;
}

// transform it into a devWorkspace template
const metadata = editorDevfile.metadata;
Expand Down
16 changes: 12 additions & 4 deletions tools/devworkspace-generator/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ export class Main {
editorPath?: string;
editorContent?: string;
editorEntry?: string;
editorUrl?: string;
pluginRegistryUrl?: string;
projects: { name: string; location: string }[];
},
axiosInstance: axios.AxiosInstance
): Promise<DevfileContext> {
if (!params.editorPath && !params.editorEntry && !params.editorContent) {
throw new Error('missing editorPath or editorEntry or editorContent');
if (!params.editorPath && !params.editorEntry && !params.editorContent && !params.editorUrl) {
throw new Error('missing editorPath or editorEntry or editorContent or editorUrl');
}
if (!params.devfilePath && !params.devfileUrl && !params.devfileContent) {
throw new Error('missing devfilePath or devfileUrl or devfileContent');
Expand Down Expand Up @@ -107,6 +108,8 @@ export class Main {
// devfile of the editor
const editorDevfile = await container.get(PluginRegistryResolver).loadDevfilePlugin(params.editorEntry);
editorContent = jsYaml.dump(editorDevfile);
} else if (params.editorUrl) {
editorContent = await container.get(UrlFetcher).fetchText(params.editorUrl);
} else {
editorContent = await fs.readFile(params.editorPath);
}
Expand Down Expand Up @@ -147,6 +150,7 @@ export class Main {
let devfileUrl: string | undefined;
let outputFile: string | undefined;
let editorPath: string | undefined;
let editorUrl: string | undefined;
let pluginRegistryUrl: string | undefined;
let editorEntry: string | undefined;
const projects: { name: string; location: string }[] = [];
Expand All @@ -168,6 +172,9 @@ export class Main {
if (arg.startsWith('--editor-path:')) {
editorPath = arg.substring('--editor-path:'.length);
}
if (arg.startsWith('--editor-url:')) {
editorUrl = arg.substring('--editor-url:'.length);
}
if (arg.startsWith('--output-file:')) {
outputFile = arg.substring('--output-file:'.length);
}
Expand All @@ -181,8 +188,8 @@ export class Main {
});

try {
if (!editorPath && !editorEntry) {
throw new Error('missing --editor-path: or --editor-entry: parameter');
if (!editorPath && !editorEntry && !editorUrl) {
throw new Error('missing --editor-path: or --editor-entry: or --editor-url: parameter');
}
if (!devfilePath && !devfileUrl) {
throw new Error('missing --devfile-path: or --devfile-url: parameter');
Expand All @@ -198,6 +205,7 @@ export class Main {
outputFile,
pluginRegistryUrl,
editorEntry,
editorUrl,
projects,
},
axios.default
Expand Down
2 changes: 1 addition & 1 deletion tools/devworkspace-generator/tests/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ describe('Test Main with stubs', () => {
} catch (e) {
message = e.message;
}
expect(message).toEqual('missing editorPath or editorEntry or editorContent');
expect(message).toEqual('missing editorPath or editorEntry or editorContent or editorUrl');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Jest is unhappy because of uncovered lines:

image

working on it, will update the PR soon...

});

test('missing devfile', async () => {
Expand Down