From a04b62d0db570757efb3835ef133177b61e47922 Mon Sep 17 00:00:00 2001 From: vitaliy-guliy Date: Thu, 19 Dec 2024 00:35:26 +0000 Subject: [PATCH 1/4] test Signed-off-by: vitaliy-guliy --- code/extensions/che-remote/src/extension.ts | 35 +++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/code/extensions/che-remote/src/extension.ts b/code/extensions/che-remote/src/extension.ts index 4a273260b98..4149d63dfbd 100644 --- a/code/extensions/che-remote/src/extension.ts +++ b/code/extensions/che-remote/src/extension.ts @@ -231,9 +231,20 @@ async function updateDevfile(cheApi: any): Promise { } try { - // keep spec.template.attributes - if (!devfileContext.devWorkspace.spec!.template!.attributes) { - devfileContext.devWorkspace.spec!.template!.attributes = flattenedDevfile.attributes; + const action = await vscode.window.showInformationMessage('Do you want to copy attributes from existing to a new devfile?', { + modal: true + }, 'Copy', 'Skip'); + console.log(`> action [${action}]`); + + if ('Copy' === action) { + // keep spec.template.attributes + if (!devfileContext.devWorkspace.spec!.template!.attributes) { + devfileContext.devWorkspace.spec!.template!.attributes = flattenedDevfile.attributes; + } + } else if (action === 'Skip') { + // do nothing + } else if (action === undefined) { + return false; } } catch (error) { await vscode.window.showErrorMessage(`Failed to update DevWorkspace attributes. ${error}`); @@ -241,6 +252,24 @@ async function updateDevfile(cheApi: any): Promise { } try { + const serialized = jsYaml.dump(devfileContext); + await fs.writeFile('/projects/new-devfile.yaml', serialized); + await vscode.window.showInformationMessage('The new devfile has been written to \'/projects/new-devfile.yaml\'', { + modal: true + }); + } catch (error) { + await vscode.window.showErrorMessage(`Failed to write new devfile context to '/projects/new-devfile.yaml'. ${error}`); + return false; + } + + try { + const action = await vscode.window.showInformationMessage('Apply changes?', { + modal: true + }, 'Apply'); + if (action !== 'Apply') { + return false; + } + await devfileService.updateDevfile(devfileContext.devWorkspace.spec?.template); } catch (error) { if (error.body && error.body.message) { From ede76838592fbe8e9a509c32d2f731fd2d9063d8 Mon Sep 17 00:00:00 2001 From: vitaliy-guliy Date: Thu, 19 Dec 2024 12:00:31 +0000 Subject: [PATCH 2/4] update Signed-off-by: vitaliy-guliy --- code/extensions/che-remote/src/extension.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/code/extensions/che-remote/src/extension.ts b/code/extensions/che-remote/src/extension.ts index 4149d63dfbd..dd2a2382bad 100644 --- a/code/extensions/che-remote/src/extension.ts +++ b/code/extensions/che-remote/src/extension.ts @@ -160,7 +160,11 @@ async function updateDevfile(cheApi: any): Promise { } = cheApi.getDevfileService(); const devWorkspaceGenerator = new DevWorkspaceGenerator(); + await new Promise(resolve => setTimeout(resolve, 500)); + let devfilePath = await selectDevfile(); + await new Promise(resolve => setTimeout(resolve, 500)); + if (`${process.env.PROJECTS_ROOT!}/*` === devfilePath) { const uri = await vscode.window.showOpenDialog({ canSelectFolders: false @@ -176,6 +180,8 @@ async function updateDevfile(cheApi: any): Promise { return false; } + await new Promise(resolve => setTimeout(resolve, 500)); + const action = await vscode.window.showInformationMessage( 'Workspace restart', { modal: true, detail: `Your workspace will be restarted from ${devfilePath}. This action is not revertable.` From 5d51a86312685f43641ec4f4e1b03a5d133f21c7 Mon Sep 17 00:00:00 2001 From: vitaliy-guliy Date: Mon, 30 Dec 2024 22:13:16 +0000 Subject: [PATCH 3/4] update Signed-off-by: vitaliy-guliy --- code/extensions/che-remote/src/extension.ts | 30 +++++++-------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/code/extensions/che-remote/src/extension.ts b/code/extensions/che-remote/src/extension.ts index dd2a2382bad..f3344fbd24d 100644 --- a/code/extensions/che-remote/src/extension.ts +++ b/code/extensions/che-remote/src/extension.ts @@ -160,11 +160,7 @@ async function updateDevfile(cheApi: any): Promise { } = cheApi.getDevfileService(); const devWorkspaceGenerator = new DevWorkspaceGenerator(); - await new Promise(resolve => setTimeout(resolve, 500)); - let devfilePath = await selectDevfile(); - await new Promise(resolve => setTimeout(resolve, 500)); - if (`${process.env.PROJECTS_ROOT!}/*` === devfilePath) { const uri = await vscode.window.showOpenDialog({ canSelectFolders: false @@ -180,8 +176,6 @@ async function updateDevfile(cheApi: any): Promise { return false; } - await new Promise(resolve => setTimeout(resolve, 500)); - const action = await vscode.window.showInformationMessage( 'Workspace restart', { modal: true, detail: `Your workspace will be restarted from ${devfilePath}. This action is not revertable.` @@ -237,20 +231,15 @@ async function updateDevfile(cheApi: any): Promise { } try { - const action = await vscode.window.showInformationMessage('Do you want to copy attributes from existing to a new devfile?', { - modal: true - }, 'Copy', 'Skip'); - console.log(`> action [${action}]`); + // keep spec.template.attributes + if (!devfileContext.devWorkspace.spec!.template!.attributes) { + devfileContext.devWorkspace.spec!.template!.attributes = {}; + } - if ('Copy' === action) { - // keep spec.template.attributes - if (!devfileContext.devWorkspace.spec!.template!.attributes) { - devfileContext.devWorkspace.spec!.template!.attributes = flattenedDevfile.attributes; + for (const key of Object.keys(flattenedDevfile.attributes)) { + if (flattenedDevfile.attributes[key]) { + devfileContext.devWorkspace.spec!.template!.attributes[key] = flattenedDevfile.attributes[key]; } - } else if (action === 'Skip') { - // do nothing - } else if (action === undefined) { - return false; } } catch (error) { await vscode.window.showErrorMessage(`Failed to update DevWorkspace attributes. ${error}`); @@ -269,8 +258,9 @@ async function updateDevfile(cheApi: any): Promise { } try { - const action = await vscode.window.showInformationMessage('Apply changes?', { - modal: true + const action = await vscode.window.showInformationMessage('The new devfile has been written to \'/projects/new-devfile.yaml\'', { + modal: true, + detail: 'Apply changes?' }, 'Apply'); if (action !== 'Apply') { return false; From f9e2233d08f5376a64772d1117d5874e58718bfe Mon Sep 17 00:00:00 2001 From: vitaliy-guliy Date: Thu, 2 Jan 2025 11:33:24 +0000 Subject: [PATCH 4/4] update Signed-off-by: vitaliy-guliy --- code/extensions/che-remote/src/extension.ts | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/code/extensions/che-remote/src/extension.ts b/code/extensions/che-remote/src/extension.ts index f3344fbd24d..958451ab8c4 100644 --- a/code/extensions/che-remote/src/extension.ts +++ b/code/extensions/che-remote/src/extension.ts @@ -247,25 +247,6 @@ async function updateDevfile(cheApi: any): Promise { } try { - const serialized = jsYaml.dump(devfileContext); - await fs.writeFile('/projects/new-devfile.yaml', serialized); - await vscode.window.showInformationMessage('The new devfile has been written to \'/projects/new-devfile.yaml\'', { - modal: true - }); - } catch (error) { - await vscode.window.showErrorMessage(`Failed to write new devfile context to '/projects/new-devfile.yaml'. ${error}`); - return false; - } - - try { - const action = await vscode.window.showInformationMessage('The new devfile has been written to \'/projects/new-devfile.yaml\'', { - modal: true, - detail: 'Apply changes?' - }, 'Apply'); - if (action !== 'Apply') { - return false; - } - await devfileService.updateDevfile(devfileContext.devWorkspace.spec?.template); } catch (error) { if (error.body && error.body.message) {