From b1d6ee384acdb951e03fdd07c0f5170be7175125 Mon Sep 17 00:00:00 2001 From: Sudhir Verma Date: Thu, 5 Dec 2019 17:52:45 +0530 Subject: [PATCH 1/2] `Tekton: Delete` commands should show confirmation info message and run without terminal --- src/tekton/clustertask.ts | 13 ++++++-- src/tekton/pipeline.ts | 12 +++++-- src/tekton/pipelineresource.ts | 13 ++++++-- src/tekton/pipelinerun.ts | 14 ++++++-- src/tekton/task.ts | 13 ++++++-- src/tekton/taskrun.ts | 2 ++ src/tkn.ts | 12 +++---- test/tekton/clustertask.test.ts | 45 +++++++++++++++++++++---- test/tekton/pipeline.test.ts | 42 +++++++++++++++++++++-- test/tekton/pipelineresource.test.ts | 45 ++++++++++++++++++++----- test/tekton/pipelinerun.test.ts | 50 +++++++++++++++++++++++----- test/tekton/task.test.ts | 42 +++++++++++++++++++++-- test/tekton/taskrun.test.ts | 44 ++++++++++++++++++++++-- 13 files changed, 298 insertions(+), 49 deletions(-) diff --git a/src/tekton/clustertask.ts b/src/tekton/clustertask.ts index fa714c7e..03d59428 100644 --- a/src/tekton/clustertask.ts +++ b/src/tekton/clustertask.ts @@ -5,6 +5,8 @@ import { TektonItem } from './tektonitem'; import { TektonNode, Command } from '../tkn'; +import { Progress } from '../util/progress'; +import { window } from 'vscode'; export class ClusterTask extends TektonItem { @@ -16,8 +18,15 @@ export class ClusterTask extends TektonItem { if (clustertasks) { ClusterTask.tkn.executeInTerminal(Command.listClusterTasksinTerminal()); } } - static async delete(clustertask: TektonNode): Promise { - if (clustertask) { ClusterTask.tkn.executeInTerminal(Command.deleteClusterTask(clustertask.getName())); } + static async delete(clustertask: TektonNode): Promise { + const value = await window.showWarningMessage(`Do you want to delete clustertask '${clustertask.getName()}\'?`, 'Yes', 'Cancel'); + if (value === 'Yes') { + return Progress.execFunctionWithProgress(`Deleting the clustertask '${clustertask.getName()}'`, () => + ClusterTask.tkn.execute(Command.deleteClusterTask(clustertask.getName()))) + .then(() => `clustertask '${clustertask.getName()}' successfully deleted`) + .catch((err) => Promise.reject(`Failed to delete clustertask with error '${err}'`)); + } + return null; } } \ No newline at end of file diff --git a/src/tekton/pipeline.ts b/src/tekton/pipeline.ts index 3407c17d..73ecad94 100644 --- a/src/tekton/pipeline.ts +++ b/src/tekton/pipeline.ts @@ -12,7 +12,6 @@ import * as cliInstance from '../cli'; import { Cli } from '../cli'; import * as k8s from 'vscode-kubernetes-tools-api'; - export interface NameType { name: string; type: string; @@ -271,8 +270,15 @@ export class Pipeline extends TektonItem { if (pipeline) { Pipeline.tkn.executeInTerminal(Command.listPipelinesInTerminal(pipeline.getName())); } } - static async delete(pipeline: TektonNode): Promise { - if (pipeline) {Pipeline.tkn.executeInTerminal(Command.deletePipeline(pipeline.getName())); } + static async delete(pipeline: TektonNode): Promise { + const value = await window.showWarningMessage(`Do you want to delete pipeline '${pipeline.getName()}\'?`, 'Yes', 'Cancel'); + if (value === 'Yes') { + return Progress.execFunctionWithProgress(`Deleting the pipeline '${pipeline.getName()}'`, () => + Pipeline.tkn.execute(Command.deletePipeline(pipeline.getName()))) + .then(() => `pipeline '${pipeline.getName()}' successfully deleted`) + .catch((err) => Promise.reject(`Failed to delete pipeline with error '${err}'`)); + } + return null; } } \ No newline at end of file diff --git a/src/tekton/pipelineresource.ts b/src/tekton/pipelineresource.ts index acbebbc9..c8890380 100644 --- a/src/tekton/pipelineresource.ts +++ b/src/tekton/pipelineresource.ts @@ -6,6 +6,8 @@ import { TektonItem } from './tektonitem'; import { TektonNode, Command } from '../tkn'; import * as k8s from 'vscode-kubernetes-tools-api'; +import { Progress } from '../util/progress'; +import { window } from 'vscode'; export class PipelineResource extends TektonItem { @@ -18,8 +20,15 @@ export class PipelineResource extends TektonItem { if (pipelineresource) { PipelineResource.tkn.executeInTerminal(Command.listPipelineResourcesInTerminal(pipelineresource.getName())); } } - static async delete(pipelineresource: TektonNode): Promise { - if (pipelineresource) { PipelineResource.tkn.executeInTerminal(Command.deletePipelineResource(pipelineresource.getName())); } + static async delete(pipelineresource: TektonNode): Promise { + const value = await window.showWarningMessage(`Do you want to delete resource '${pipelineresource.getName()}\'?`, 'Yes', 'Cancel'); + if (value === 'Yes') { + return Progress.execFunctionWithProgress(`Deleting the resource '${pipelineresource.getName()}'`, () => + PipelineResource.tkn.execute(Command.deletePipelineResource(pipelineresource.getName()))) + .then(() => `resource '${pipelineresource.getName()}' successfully deleted`) + .catch((err) => Promise.reject(`Failed to delete resource with error '${err}'`)); + } + return null; } } \ No newline at end of file diff --git a/src/tekton/pipelinerun.ts b/src/tekton/pipelinerun.ts index ff6ebe0a..4623825a 100644 --- a/src/tekton/pipelinerun.ts +++ b/src/tekton/pipelinerun.ts @@ -5,7 +5,8 @@ import { TektonItem } from './tektonitem'; import { TektonNode, Command } from '../tkn'; -import * as k8s from 'vscode-kubernetes-tools-api'; +import { window } from 'vscode'; +import { Progress } from '../util/progress'; export class PipelineRun extends TektonItem { @@ -48,8 +49,15 @@ export class PipelineRun extends TektonItem { if (pipelinerun) { PipelineRun.tkn.executeInTerminal(Command.cancelPipelineRun(pipelinerun.getName())); } } - static async delete(pipelinerun: TektonNode): Promise { - if (pipelinerun) { PipelineRun.tkn.executeInTerminal(Command.deletePipelineRun(pipelinerun.getName())); } + static async delete(pipelinerun: TektonNode): Promise { + const value = await window.showWarningMessage(`Do you want to delete pipelinerun '${pipelinerun.getName()}\'?`, 'Yes', 'Cancel'); + if (value === 'Yes') { + return Progress.execFunctionWithProgress(`Deleting the pipelinerun '${pipelinerun.getName()}'`, () => + PipelineRun.tkn.execute(Command.deletePipelineRun(pipelinerun.getName()))) + .then(() => `pipelinerun '${pipelinerun.getName()}' successfully deleted`) + .catch((err) => Promise.reject(`Failed to delete pipelinerun with error '${err}'`)); + } + return null; } } \ No newline at end of file diff --git a/src/tekton/task.ts b/src/tekton/task.ts index 07860574..d55fe1ed 100644 --- a/src/tekton/task.ts +++ b/src/tekton/task.ts @@ -5,6 +5,8 @@ import { TektonItem } from './tektonitem'; import { TektonNode, Command } from '../tkn'; +import { window } from 'vscode'; +import { Progress } from '../util/progress'; export class Task extends TektonItem { @@ -18,7 +20,14 @@ export class Task extends TektonItem { if (task) { Task.tkn.executeInTerminal(Command.listTasksinTerminal()); } } - static async delete(task: TektonNode): Promise { - if (task) { Task.tkn.executeInTerminal(Command.deleteTask(task.getName())); } + static async delete(task: TektonNode): Promise { + const value = await window.showWarningMessage(`Do you want to delete task '${task.getName()}\'?`, 'Yes', 'Cancel'); + if (value === 'Yes') { + return Progress.execFunctionWithProgress(`Deleting the task '${task.getName()}'`, () => + Task.tkn.execute(Command.deleteTask(task.getName()))) + .then(() => `task '${task.getName()}' successfully deleted`) + .catch((err) => Promise.reject(`Failed to delete task with error '${err}'`)); + } + return null; } } \ No newline at end of file diff --git a/src/tekton/taskrun.ts b/src/tekton/taskrun.ts index b5833a19..b0e41e02 100644 --- a/src/tekton/taskrun.ts +++ b/src/tekton/taskrun.ts @@ -5,6 +5,8 @@ import { TektonItem } from './tektonitem'; import { TektonNode, Command } from '../tkn'; +import { window } from 'vscode'; +import { Progress } from '../util/progress'; export class TaskRun extends TektonItem { diff --git a/src/tkn.ts b/src/tkn.ts index 6f9351b9..2f0466ab 100644 --- a/src/tkn.ts +++ b/src/tkn.ts @@ -110,7 +110,7 @@ export class Command { } @verbose static deletePipeline(name: string) { - return `tkn pipeline delete ${name}`; + return `tkn pipeline delete ${name} -f`; } @verbose static listPipelineResources() { @@ -126,7 +126,7 @@ export class Command { } @verbose static deletePipelineResource(name: string) { - return `tkn resource delete ${name}`; + return `tkn resource delete ${name} -f`; } @verbose static listPipelines() { @@ -158,7 +158,7 @@ export class Command { } @verbose static deletePipelineRun(name: string) { - return `tkn pipelinerun delete ${name}`; + return `tkn pipelinerun delete ${name} -f`; } @verbose static showPipelineRunLogs(name: string) { @@ -182,7 +182,7 @@ export class Command { } @verbose static deleteTask(name: string) { - return `tkn task delete ${name}`; + return `tkn task delete ${name} -f`; } @verbose static listClusterTasks(namespace?: string) { @@ -193,7 +193,7 @@ export class Command { } @verbose static deleteClusterTask(name: string) { - return `tkn task delete ${name}`; + return `tkn clustertask delete ${name} -f`; } @verbose static showTaskRunLogs(name: string) { @@ -201,7 +201,7 @@ export class Command { } @verbose static deleteTaskRun(name: string) { - return `tkn taskrun delete ${name}`; + return `tkn taskrun delete ${name} -f`; } @verbose static printTknVersion() { diff --git a/test/tekton/clustertask.test.ts b/test/tekton/clustertask.test.ts index 3c747db9..e1639c5e 100644 --- a/test/tekton/clustertask.test.ts +++ b/test/tekton/clustertask.test.ts @@ -18,6 +18,7 @@ const expect = chai.expect; chai.use(sinonChai); suite('Tekton/Clustertask', () => { + let execStub: sinon.SinonStub; let sandbox: sinon.SinonSandbox; let getClusterTaskStub: sinon.SinonStub; const clustertaskNode = new TestItem(TknImpl.ROOT, 'test-clustertask', ContextType.CLUSTERTASK, null); @@ -26,6 +27,7 @@ suite('Tekton/Clustertask', () => { setup(() => { sandbox = sinon.createSandbox(); + execStub = sandbox.stub(TknImpl.prototype, 'execute').resolves({error: null, stdout: '', stderr: ''}); sandbox.stub(TknImpl.prototype, 'getClusterTasks').resolves([clustertaskItem]); getClusterTaskStub = sandbox.stub(TektonItem, 'getClusterTaskNames').resolves([clustertaskItem]); sandbox.stub(vscode.window, 'showInputBox'); @@ -68,16 +70,47 @@ suite('Tekton/Clustertask', () => { }); - suite('delete', () => { - let termStub: sinon.SinonStub; + suite('delete command', () => { + let warnStub: sinon.SinonStub; - setup(() => { - termStub = sandbox.stub(TknImpl.prototype, 'executeInTerminal').resolves(); + setup(() => { + warnStub = sandbox.stub(vscode.window, 'showWarningMessage'); }); - test('delete calls the correct tkn command in terminal', async () => { + test('calls the appropriate tkn command if confirmed', async () => { + warnStub.resolves('Yes'); + await ClusterTask.delete(clustertaskItem); - expect(termStub).calledOnceWith(Command.deleteTask(clustertaskItem.getName())); + + expect(execStub).calledOnceWith(Command.deleteClusterTask(clustertaskItem.getName())); + }); + + test('returns a confirmation message text when successful', async () => { + warnStub.resolves('Yes'); + + const result = await ClusterTask.delete(clustertaskItem); + + expect(result).equals(`clustertask '${clustertaskItem.getName()}' successfully deleted`); + }); + + test('returns null when cancelled', async() => { + warnStub.resolves('Cancel'); + + const result = await ClusterTask.delete(clustertaskItem); + + expect(result).null; + }); + + test('throws an error message when command failed', async () => { + warnStub.resolves('Yes'); + execStub.rejects('ERROR'); + let expectedError; + try { + await ClusterTask.delete(clustertaskItem); + } catch (err) { + expectedError = err; + } + expect(expectedError).equals(`Failed to delete clustertask with error 'ERROR'`); }); }); diff --git a/test/tekton/pipeline.test.ts b/test/tekton/pipeline.test.ts index 7f71fdb7..a3cad9ab 100644 --- a/test/tekton/pipeline.test.ts +++ b/test/tekton/pipeline.test.ts @@ -107,13 +107,49 @@ suite('Tekton/Pipeline', () => { }); }); - suite('delete', () => { - test('describe calls the correct tkn command in terminal', async () => { + suite('delete command', () => { + let warnStub: sinon.SinonStub; + + setup(() => { + warnStub = sandbox.stub(vscode.window, 'showWarningMessage'); + }); + + test('calls the appropriate tkn command if confirmed', async () => { + warnStub.resolves('Yes'); + await Pipeline.delete(pipelineItem); - expect(termStub).calledOnceWith(Command.deletePipeline(pipelineItem.getName())); + + expect(execStub).calledOnceWith(Command.deletePipeline(pipelineItem.getName())); + }); + + test('returns a confirmation message text when successful', async () => { + warnStub.resolves('Yes'); + + const result = await Pipeline.delete(pipelineItem); + + expect(result).equals(`pipeline '${pipelineItem.getName()}' successfully deleted`); + }); + + test('returns null when cancelled', async() => { + warnStub.resolves('Cancel'); + + const result = await Pipeline.delete(pipelineItem); + + expect(result).null; }); + test('throws an error message when command failed', async () => { + warnStub.resolves('Yes'); + execStub.rejects('ERROR'); + let expectedError; + try { + await Pipeline.delete(pipelineItem); + } catch (err) { + expectedError = err; + } + expect(expectedError).equals(`Failed to delete pipeline with error 'ERROR'`); + }); }); suite('restart', () => { diff --git a/test/tekton/pipelineresource.test.ts b/test/tekton/pipelineresource.test.ts index be6dc6fa..f0cbb145 100644 --- a/test/tekton/pipelineresource.test.ts +++ b/test/tekton/pipelineresource.test.ts @@ -11,7 +11,6 @@ import * as sinonChai from 'sinon-chai'; import * as sinon from 'sinon'; import { TknImpl, Command, ContextType } from '../../src/tkn'; import { PipelineResource } from '../../src/tekton/pipelineresource'; -import { Pipeline } from '../../src/tekton/pipeline'; import { TestItem } from './testTektonitem'; import { TektonItem } from '../../src/tekton/tektonitem'; @@ -98,20 +97,48 @@ suite('Tekton/PipelineResource', () => { }); - suite('delete', () => { - - - test('returns null when cancelled', async () => { - const result = await PipelineResource.delete(null); + suite('delete command', () => { + let warnStub: sinon.SinonStub; - expect(result).undefined; + setup(() => { + warnStub = sandbox.stub(vscode.window, 'showWarningMessage'); }); - test('describe calls the correct tkn command in terminal', async () => { + test('calls the appropriate tkn command if confirmed', async () => { + warnStub.resolves('Yes'); + await PipelineResource.delete(pipelineresourceItem); - expect(termStub).calledOnceWith(Command.deletePipelineResource(pipelineresourceItem.getName())); + + expect(execStub).calledOnceWith(Command.deletePipelineResource(pipelineresourceItem.getName())); }); + test('returns a confirmation message text when successful', async () => { + warnStub.resolves('Yes'); + + const result = await PipelineResource.delete(pipelineresourceItem); + + expect(result).equals(`resource '${pipelineresourceItem.getName()}' successfully deleted`); + }); + + test('returns null when cancelled', async() => { + warnStub.resolves('Cancel'); + + const result = await PipelineResource.delete(pipelineresourceItem); + + expect(result).null; + }); + + test('throws an error message when command failed', async () => { + warnStub.resolves('Yes'); + execStub.rejects('ERROR'); + let expectedError; + try { + await PipelineResource.delete(pipelineresourceItem); + } catch (err) { + expectedError = err; + } + expect(expectedError).equals(`Failed to delete resource with error 'ERROR'`); + }); }); }); diff --git a/test/tekton/pipelinerun.test.ts b/test/tekton/pipelinerun.test.ts index cc27fc35..1e0cf604 100644 --- a/test/tekton/pipelinerun.test.ts +++ b/test/tekton/pipelinerun.test.ts @@ -11,7 +11,6 @@ import * as sinonChai from 'sinon-chai'; import * as sinon from 'sinon'; import { TknImpl, Command, ContextType } from '../../src/tkn'; import { PipelineRun } from '../../src/tekton/pipelinerun'; -import { Pipeline } from '../../src/tekton/pipeline'; import { TestItem } from './testTektonitem'; import { TektonItem } from '../../src/tekton/tektonitem'; @@ -144,13 +143,48 @@ suite('Tekton/PipelineRun', () => { }); - suite('delete', () => { - - test('describe calls the correct tkn command in terminal', async () => { - await PipelineRun.delete(pipelineItem); - expect(termStub).calledOnceWith(Command.deletePipelineRun(pipelineItem.getName())); + suite('delete command', () => { + let warnStub: sinon.SinonStub; + + setup(() => { + warnStub = sandbox.stub(vscode.window, 'showWarningMessage'); + }); + + test('calls the appropriate tkn command if confirmed', async () => { + warnStub.resolves('Yes'); + + await PipelineRun.delete(pipelinerunItem); + + expect(execStub).calledOnceWith(Command.deletePipelineRun(pipelinerunItem.getName())); + }); + + test('returns a confirmation message text when successful', async () => { + warnStub.resolves('Yes'); + + const result = await PipelineRun.delete(pipelinerunItem); + + expect(result).equals(`pipelinerun '${pipelinerunItem.getName()}' successfully deleted`); + }); + + test('returns null when cancelled', async() => { + warnStub.resolves('Cancel'); + + const result = await PipelineRun.delete(pipelinerunItem); + + expect(result).null; + }); + + test('throws an error message when command failed', async () => { + warnStub.resolves('Yes'); + execStub.rejects('ERROR'); + let expectedError; + try { + await PipelineRun.delete(pipelinerunItem); + } catch (err) { + expectedError = err; + } + expect(expectedError).equals(`Failed to delete pipelinerun with error 'ERROR'`); + }); }); - - }); }); }); diff --git a/test/tekton/task.test.ts b/test/tekton/task.test.ts index 85f73bea..1dfbae3e 100644 --- a/test/tekton/task.test.ts +++ b/test/tekton/task.test.ts @@ -66,11 +66,47 @@ suite('Tekton/Task', () => { }); }); - suite('delete', () => { + suite('delete command', () => { + let warnStub: sinon.SinonStub; + + setup(() => { + warnStub = sandbox.stub(vscode.window, 'showWarningMessage'); + }); + + test('calls the appropriate tkn command if confirmed', async () => { + warnStub.resolves('Yes'); - test('delete calls the correct tkn command in terminal', async () => { await Task.delete(taskItem); - expect(termStub).calledOnceWith(Command.deleteTask(taskItem.getName())); + + expect(execStub).calledOnceWith(Command.deleteTask(taskItem.getName())); + }); + + test('returns a confirmation message text when successful', async () => { + warnStub.resolves('Yes'); + + const result = await Task.delete(taskItem); + + expect(result).equals(`task '${taskItem.getName()}' successfully deleted`); + }); + + test('returns null when cancelled', async() => { + warnStub.resolves('Cancel'); + + const result = await Task.delete(taskItem); + + expect(result).null; + }); + + test('throws an error message when command failed', async () => { + warnStub.resolves('Yes'); + execStub.rejects('ERROR'); + let expectedError; + try { + await Task.delete(taskItem); + } catch (err) { + expectedError = err; + } + expect(expectedError).equals(`Failed to delete task with error 'ERROR'`); }); }); }); diff --git a/test/tekton/taskrun.test.ts b/test/tekton/taskrun.test.ts index 7d2b4b79..f5151fc8 100644 --- a/test/tekton/taskrun.test.ts +++ b/test/tekton/taskrun.test.ts @@ -19,6 +19,7 @@ chai.use(sinonChai); suite('Tekton/TaskRun', () => { let sandbox: sinon.SinonSandbox; + let execStub: sinon.SinonStub; let getTaskRunsStub: sinon.SinonStub; let getPipelineRunNamesStub: sinon.SinonStub; const pipelineItem = new TestItem(null, 'pipeline', ContextType.PIPELINE); @@ -27,6 +28,7 @@ suite('Tekton/TaskRun', () => { setup(() => { sandbox = sinon.createSandbox(); + execStub = sandbox.stub(TknImpl.prototype, 'execute').resolves({error: null, stdout: '', stderr: ''}); sandbox.stub(TknImpl.prototype, 'getTaskRuns').resolves([taskrunItem]); getPipelineRunNamesStub = sandbox.stub(TektonItem, 'getPipelinerunNames').resolves([pipelinerunItem]); sandbox.stub(vscode.window, 'showInputBox'); @@ -141,9 +143,47 @@ suite('Tekton/TaskRun', () => { suite('delete', () => { - test('delete calls the correct tkn command in terminal', async () => { + suite('delete command', () => { + let warnStub: sinon.SinonStub; + + setup(() => { + warnStub = sandbox.stub(vscode.window, 'showWarningMessage'); + }); + + test('calls the appropriate tkn command if confirmed', async () => { + warnStub.resolves('Yes'); + await TaskRun.delete(taskrunItem); - expect(termStub).calledOnceWith(Command.deleteTaskRun(taskrunItem.getName())); + + expect(execStub).calledOnceWith(Command.deleteTaskRun(taskrunItem.getName())); + }); + + test('returns a confirmation message text when successful', async () => { + warnStub.resolves('Yes'); + + const result = await TaskRun.delete(taskrunItem); + + expect(result).equals(`taskrun '${taskrunItem.getName()}' successfully deleted`); + }); + + test('returns null when cancelled', async() => { + warnStub.resolves('Cancel'); + + const result = await TaskRun.delete(taskrunItem); + + expect(result).null; + }); + + test('throws an error message when command failed', async () => { + warnStub.resolves('Yes'); + execStub.rejects('ERROR'); + let expectedError; + try { + await TaskRun.delete(taskrunItem); + } catch (err) { + expectedError = err; + } + expect(expectedError).equals(`Failed to delete taskrun with error 'ERROR'`); }); }); }); From a7c42c9a867419b9e893948430fdfad4819bff9b Mon Sep 17 00:00:00 2001 From: Sudhir Verma Date: Tue, 10 Dec 2019 16:40:01 +0530 Subject: [PATCH 2/2] Fix review changes --- src/tekton/clustertask.ts | 8 ++++---- src/tekton/pipeline.ts | 8 ++++---- src/tekton/pipelineresource.ts | 8 ++++---- src/tekton/pipelinerun.ts | 8 ++++---- src/tekton/task.ts | 8 ++++---- src/tekton/taskrun.ts | 11 +++++++++-- test/tekton/clustertask.test.ts | 4 ++-- test/tekton/pipeline.test.ts | 4 ++-- test/tekton/pipelineresource.test.ts | 4 ++-- test/tekton/pipelinerun.test.ts | 4 ++-- test/tekton/task.test.ts | 4 ++-- test/tekton/taskrun.test.ts | 6 ++---- 12 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/tekton/clustertask.ts b/src/tekton/clustertask.ts index 03d59428..65631df4 100644 --- a/src/tekton/clustertask.ts +++ b/src/tekton/clustertask.ts @@ -19,12 +19,12 @@ export class ClusterTask extends TektonItem { } static async delete(clustertask: TektonNode): Promise { - const value = await window.showWarningMessage(`Do you want to delete clustertask '${clustertask.getName()}\'?`, 'Yes', 'Cancel'); + const value = await window.showWarningMessage(`Do you want to delete the ClusterTask '${clustertask.getName()}\'?`, 'Yes', 'Cancel'); if (value === 'Yes') { - return Progress.execFunctionWithProgress(`Deleting the clustertask '${clustertask.getName()}'`, () => + return Progress.execFunctionWithProgress(`Deleting the ClusterTask '${clustertask.getName()}'.`, () => ClusterTask.tkn.execute(Command.deleteClusterTask(clustertask.getName()))) - .then(() => `clustertask '${clustertask.getName()}' successfully deleted`) - .catch((err) => Promise.reject(`Failed to delete clustertask with error '${err}'`)); + .then(() => `The ClusterTask '${clustertask.getName()}' successfully deleted.`) + .catch((err) => Promise.reject(`Failed to delete the ClusterTask '${clustertask.getName()}': '${err}'.`)); } return null; } diff --git a/src/tekton/pipeline.ts b/src/tekton/pipeline.ts index 73ecad94..cabdf21a 100644 --- a/src/tekton/pipeline.ts +++ b/src/tekton/pipeline.ts @@ -271,12 +271,12 @@ export class Pipeline extends TektonItem { } static async delete(pipeline: TektonNode): Promise { - const value = await window.showWarningMessage(`Do you want to delete pipeline '${pipeline.getName()}\'?`, 'Yes', 'Cancel'); + const value = await window.showWarningMessage(`Do you want to delete the Pipeline '${pipeline.getName()}\'?`, 'Yes', 'Cancel'); if (value === 'Yes') { - return Progress.execFunctionWithProgress(`Deleting the pipeline '${pipeline.getName()}'`, () => + return Progress.execFunctionWithProgress(`Deleting the Pipeline '${pipeline.getName()}'.`, () => Pipeline.tkn.execute(Command.deletePipeline(pipeline.getName()))) - .then(() => `pipeline '${pipeline.getName()}' successfully deleted`) - .catch((err) => Promise.reject(`Failed to delete pipeline with error '${err}'`)); + .then(() => `The Pipeline '${pipeline.getName()}' successfully deleted.`) + .catch((err) => Promise.reject(`Failed to delete the Pipeline '${pipeline.getName()}': '${err}'.`)); } return null; } diff --git a/src/tekton/pipelineresource.ts b/src/tekton/pipelineresource.ts index c8890380..9875eecb 100644 --- a/src/tekton/pipelineresource.ts +++ b/src/tekton/pipelineresource.ts @@ -21,12 +21,12 @@ export class PipelineResource extends TektonItem { } static async delete(pipelineresource: TektonNode): Promise { - const value = await window.showWarningMessage(`Do you want to delete resource '${pipelineresource.getName()}\'?`, 'Yes', 'Cancel'); + const value = await window.showWarningMessage(`Do you want to delete the Resource '${pipelineresource.getName()}\'?`, 'Yes', 'Cancel'); if (value === 'Yes') { - return Progress.execFunctionWithProgress(`Deleting the resource '${pipelineresource.getName()}'`, () => + return Progress.execFunctionWithProgress(`Deleting the Resource '${pipelineresource.getName()}'.`, () => PipelineResource.tkn.execute(Command.deletePipelineResource(pipelineresource.getName()))) - .then(() => `resource '${pipelineresource.getName()}' successfully deleted`) - .catch((err) => Promise.reject(`Failed to delete resource with error '${err}'`)); + .then(() => `The Resource '${pipelineresource.getName()}' successfully deleted.`) + .catch((err) => Promise.reject(`Failed to delete the Resource '${pipelineresource.getName()}': '${err}'.`)); } return null; } diff --git a/src/tekton/pipelinerun.ts b/src/tekton/pipelinerun.ts index 4623825a..7a1a166b 100644 --- a/src/tekton/pipelinerun.ts +++ b/src/tekton/pipelinerun.ts @@ -50,12 +50,12 @@ export class PipelineRun extends TektonItem { } static async delete(pipelinerun: TektonNode): Promise { - const value = await window.showWarningMessage(`Do you want to delete pipelinerun '${pipelinerun.getName()}\'?`, 'Yes', 'Cancel'); + const value = await window.showWarningMessage(`Do you want to delete the PipelineRun '${pipelinerun.getName()}\'?`, 'Yes', 'Cancel'); if (value === 'Yes') { - return Progress.execFunctionWithProgress(`Deleting the pipelinerun '${pipelinerun.getName()}'`, () => + return Progress.execFunctionWithProgress(`Deleting the PipelineRun '${pipelinerun.getName()}'.`, () => PipelineRun.tkn.execute(Command.deletePipelineRun(pipelinerun.getName()))) - .then(() => `pipelinerun '${pipelinerun.getName()}' successfully deleted`) - .catch((err) => Promise.reject(`Failed to delete pipelinerun with error '${err}'`)); + .then(() => `The PipelineRun '${pipelinerun.getName()}' successfully deleted.`) + .catch((err) => Promise.reject(`Failed to delete the PipelineRun '${pipelinerun.getName()}': '${err}'.`)); } return null; } diff --git a/src/tekton/task.ts b/src/tekton/task.ts index d55fe1ed..532cc81d 100644 --- a/src/tekton/task.ts +++ b/src/tekton/task.ts @@ -21,12 +21,12 @@ export class Task extends TektonItem { } static async delete(task: TektonNode): Promise { - const value = await window.showWarningMessage(`Do you want to delete task '${task.getName()}\'?`, 'Yes', 'Cancel'); + const value = await window.showWarningMessage(`Do you want to delete the Task '${task.getName()}\'?`, 'Yes', 'Cancel'); if (value === 'Yes') { - return Progress.execFunctionWithProgress(`Deleting the task '${task.getName()}'`, () => + return Progress.execFunctionWithProgress(`Deleting the Task '${task.getName()}'.`, () => Task.tkn.execute(Command.deleteTask(task.getName()))) - .then(() => `task '${task.getName()}' successfully deleted`) - .catch((err) => Promise.reject(`Failed to delete task with error '${err}'`)); + .then(() => `The Task '${task.getName()}' successfully deleted.`) + .catch((err) => Promise.reject(`Failed to delete the Task '${task.getName()}': '${err}'.`)); } return null; } diff --git a/src/tekton/taskrun.ts b/src/tekton/taskrun.ts index b0e41e02..deb86eb9 100644 --- a/src/tekton/taskrun.ts +++ b/src/tekton/taskrun.ts @@ -26,7 +26,14 @@ export class TaskRun extends TektonItem { TaskRun.tkn.executeInTerminal(Command.showTaskRunFollowLogs(taskrun.getName())); } - static async delete(taskrun: TektonNode): Promise { - if (taskrun) { TaskRun.tkn.executeInTerminal(Command.deleteTaskRun(taskrun.getName())); } + static async delete(taskrun: TektonNode): Promise { + const value = await window.showWarningMessage(`Do you want to delete the TaskRun '${taskrun.getName()}\'?`, 'Yes', 'Cancel'); + if (value === 'Yes') { + return Progress.execFunctionWithProgress(`Deleting the TaskRun '${taskrun.getName()}'.`, () => + TaskRun.tkn.execute(Command.deleteTaskRun(taskrun.getName()))) + .then(() => `The TaskRun '${taskrun.getName()}' successfully deleted.`) + .catch((err) => Promise.reject(`Failed to delete the TaskRun '${taskrun.getName()}': '${err}'.`)); + } + return null; } } \ No newline at end of file diff --git a/test/tekton/clustertask.test.ts b/test/tekton/clustertask.test.ts index e1639c5e..80052c26 100644 --- a/test/tekton/clustertask.test.ts +++ b/test/tekton/clustertask.test.ts @@ -90,7 +90,7 @@ suite('Tekton/Clustertask', () => { const result = await ClusterTask.delete(clustertaskItem); - expect(result).equals(`clustertask '${clustertaskItem.getName()}' successfully deleted`); + expect(result).equals(`The ClusterTask '${clustertaskItem.getName()}' successfully deleted.`); }); test('returns null when cancelled', async() => { @@ -110,7 +110,7 @@ suite('Tekton/Clustertask', () => { } catch (err) { expectedError = err; } - expect(expectedError).equals(`Failed to delete clustertask with error 'ERROR'`); + expect(expectedError).equals(`Failed to delete the ClusterTask '${clustertaskItem.getName()}': 'ERROR'.`); }); }); diff --git a/test/tekton/pipeline.test.ts b/test/tekton/pipeline.test.ts index a3cad9ab..d26419eb 100644 --- a/test/tekton/pipeline.test.ts +++ b/test/tekton/pipeline.test.ts @@ -128,7 +128,7 @@ suite('Tekton/Pipeline', () => { const result = await Pipeline.delete(pipelineItem); - expect(result).equals(`pipeline '${pipelineItem.getName()}' successfully deleted`); + expect(result).equals(`The Pipeline '${pipelineItem.getName()}' successfully deleted.`); }); test('returns null when cancelled', async() => { @@ -148,7 +148,7 @@ suite('Tekton/Pipeline', () => { } catch (err) { expectedError = err; } - expect(expectedError).equals(`Failed to delete pipeline with error 'ERROR'`); + expect(expectedError).equals(`Failed to delete the Pipeline '${pipelineItem.getName()}': 'ERROR'.`); }); }); diff --git a/test/tekton/pipelineresource.test.ts b/test/tekton/pipelineresource.test.ts index f0cbb145..4f8761fa 100644 --- a/test/tekton/pipelineresource.test.ts +++ b/test/tekton/pipelineresource.test.ts @@ -117,7 +117,7 @@ suite('Tekton/PipelineResource', () => { const result = await PipelineResource.delete(pipelineresourceItem); - expect(result).equals(`resource '${pipelineresourceItem.getName()}' successfully deleted`); + expect(result).equals(`The Resource '${pipelineresourceItem.getName()}' successfully deleted.`); }); test('returns null when cancelled', async() => { @@ -137,7 +137,7 @@ suite('Tekton/PipelineResource', () => { } catch (err) { expectedError = err; } - expect(expectedError).equals(`Failed to delete resource with error 'ERROR'`); + expect(expectedError).equals(`Failed to delete the Resource '${pipelineresourceItem.getName()}': 'ERROR'.`); }); }); diff --git a/test/tekton/pipelinerun.test.ts b/test/tekton/pipelinerun.test.ts index 1e0cf604..43fe4591 100644 --- a/test/tekton/pipelinerun.test.ts +++ b/test/tekton/pipelinerun.test.ts @@ -163,7 +163,7 @@ suite('Tekton/PipelineRun', () => { const result = await PipelineRun.delete(pipelinerunItem); - expect(result).equals(`pipelinerun '${pipelinerunItem.getName()}' successfully deleted`); + expect(result).equals(`The PipelineRun '${pipelinerunItem.getName()}' successfully deleted.`); }); test('returns null when cancelled', async() => { @@ -183,7 +183,7 @@ suite('Tekton/PipelineRun', () => { } catch (err) { expectedError = err; } - expect(expectedError).equals(`Failed to delete pipelinerun with error 'ERROR'`); + expect(expectedError).equals(`Failed to delete the PipelineRun '${pipelinerunItem.getName()}': 'ERROR'.`); }); }); }); diff --git a/test/tekton/task.test.ts b/test/tekton/task.test.ts index 1dfbae3e..466af0e5 100644 --- a/test/tekton/task.test.ts +++ b/test/tekton/task.test.ts @@ -86,7 +86,7 @@ suite('Tekton/Task', () => { const result = await Task.delete(taskItem); - expect(result).equals(`task '${taskItem.getName()}' successfully deleted`); + expect(result).equals(`The Task '${taskItem.getName()}' successfully deleted.`); }); test('returns null when cancelled', async() => { @@ -106,7 +106,7 @@ suite('Tekton/Task', () => { } catch (err) { expectedError = err; } - expect(expectedError).equals(`Failed to delete task with error 'ERROR'`); + expect(expectedError).equals(`Failed to delete the Task '${taskItem.getName()}': 'ERROR'.`); }); }); }); diff --git a/test/tekton/taskrun.test.ts b/test/tekton/taskrun.test.ts index f5151fc8..97066042 100644 --- a/test/tekton/taskrun.test.ts +++ b/test/tekton/taskrun.test.ts @@ -141,8 +141,6 @@ suite('Tekton/TaskRun', () => { }); - suite('delete', () => { - suite('delete command', () => { let warnStub: sinon.SinonStub; @@ -163,7 +161,7 @@ suite('Tekton/TaskRun', () => { const result = await TaskRun.delete(taskrunItem); - expect(result).equals(`taskrun '${taskrunItem.getName()}' successfully deleted`); + expect(result).equals(`The TaskRun '${taskrunItem.getName()}' successfully deleted.`); }); test('returns null when cancelled', async() => { @@ -183,7 +181,7 @@ suite('Tekton/TaskRun', () => { } catch (err) { expectedError = err; } - expect(expectedError).equals(`Failed to delete taskrun with error 'ERROR'`); + expect(expectedError).equals(`Failed to delete the TaskRun '${taskrunItem.getName()}': 'ERROR'.`); }); }); });