diff --git a/src/pipeline/wizard.ts b/src/pipeline/wizard.ts index 8823acb9..14e7778f 100644 --- a/src/pipeline/wizard.ts +++ b/src/pipeline/wizard.ts @@ -10,6 +10,7 @@ import { Disposable } from '../util/disposable'; import { debounce } from 'debounce'; import { TknResourceItem } from '../tekton/webviewstartpipeline'; import { TektonItem } from '../tekton/tektonitem'; +import { startPipeline } from '../tekton/startpipeline'; export interface PipelineWizardInput { readonly resourceColumn: vscode.ViewColumn; @@ -53,7 +54,7 @@ export class PipelineWizard extends Disposable { // eslint-disable-next-line no-case-declarations const inputStartPipeline = e.body; this.dispose(); - return await TektonItem.startPipeline(inputStartPipeline); + return await startPipeline(inputStartPipeline); } })); diff --git a/src/tekton/pipeline.ts b/src/tekton/pipeline.ts index 253df64b..7238e559 100644 --- a/src/tekton/pipeline.ts +++ b/src/tekton/pipeline.ts @@ -13,6 +13,7 @@ import { TknPipelineTrigger } from '../tekton'; import { Trigger, PipelineContent } from './pipelinecontent'; import { PipelineWizard } from '../pipeline/wizard'; import { pipelineData } from './webviewstartpipeline'; +import { startPipeline } from './startpipeline'; export class Pipeline extends TektonItem { @@ -42,7 +43,7 @@ export class Pipeline extends TektonItem { })).filter((obj) => obj.name === pipeline.getName()); const inputStartPipeline = await PipelineContent.startObject(pipelineTrigger, 'Pipeline'); - return await Pipeline.startPipeline(inputStartPipeline); + return await startPipeline(inputStartPipeline); } else { Pipeline.startWizard(pipeline); } @@ -108,7 +109,7 @@ export class Pipeline extends TektonItem { } const trigger = await pipelineData(data); if (!trigger.workspaces && !trigger.resources && !trigger.params) { - await Pipeline.startPipeline(trigger); + await startPipeline(trigger); } else { PipelineWizard.create({ trigger, resourceColumn: ViewColumn.Active }, ViewColumn.Active); } diff --git a/src/tekton/startpipeline.ts b/src/tekton/startpipeline.ts new file mode 100644 index 00000000..9242713f --- /dev/null +++ b/src/tekton/startpipeline.ts @@ -0,0 +1,22 @@ +/*----------------------------------------------------------------------------------------------- + * Copyright (c) Red Hat, Inc. All rights reserved. + * Licensed under the MIT License. See LICENSE file in the project root for license information. + *-----------------------------------------------------------------------------------------------*/ + +import { StartObject } from './pipelinecontent'; +import { Progress } from '../util/progress'; +import { TektonItem } from './tektonitem'; +import { showPipelineRunPreview } from '../pipeline/pipeline-preview'; + + + +export function startPipeline(inputStartPipeline: StartObject): Promise { + return Progress.execFunctionWithProgress(`Starting Pipeline '${inputStartPipeline.name}'.`, () => + TektonItem.tkn.startPipeline(inputStartPipeline) + .then(() => TektonItem.explorer.refresh()) + .then(() => !TektonItem.startQuickPick() ? TektonItem.ShowPipelineRun() ? TektonItem.tkn._getPipelineRuns(undefined ,inputStartPipeline.name) : undefined : undefined) + .then((value) => !TektonItem.startQuickPick() ? TektonItem.ShowPipelineRun() ? showPipelineRunPreview(value[0].getName()) : undefined : undefined) + .then(() => `Pipeline '${inputStartPipeline.name}' successfully started`) + .catch((error) => Promise.reject(`Failed to start Pipeline with error '${error}'`)) + ); +} diff --git a/src/tekton/tektonitem.ts b/src/tekton/tektonitem.ts index 882a1c22..dea7e491 100644 --- a/src/tekton/tektonitem.ts +++ b/src/tekton/tektonitem.ts @@ -7,10 +7,6 @@ import { Tkn, tkn as tknImpl, TektonNode, ContextType } from '../tkn'; import { PipelineExplorer, pipelineExplorer } from '../pipeline/pipelineExplorer'; import { workspace, window } from 'vscode'; import { tektonFSUri } from '../util/tekton-vfs'; -import { Progress } from '../util/progress'; -import { PipelineWizard } from '../pipeline/wizard'; -import { showPipelineRunPreview } from '../pipeline/pipeline-preview'; -import { StartObject } from './pipelinecontent'; const errorMessage = { Pipeline: 'You need at least one Pipeline available. Please create new Tekton Pipeline and try again.', @@ -142,15 +138,4 @@ export abstract class TektonItem { .getConfiguration('vs-tekton') .get('pipelineRun'); } - - static startPipeline(inputStartPipeline: StartObject): Promise { - return Progress.execFunctionWithProgress(`Starting Pipeline '${inputStartPipeline.name}'.`, () => - TektonItem.tkn.startPipeline(inputStartPipeline) - .then(() => TektonItem.explorer.refresh()) - .then(() => !TektonItem.startQuickPick() ? TektonItem.ShowPipelineRun() ? this.tkn._getPipelineRuns(undefined ,inputStartPipeline.name) : undefined : undefined) - .then((value) => !TektonItem.startQuickPick() ? TektonItem.ShowPipelineRun() ? showPipelineRunPreview(value[0].getName()) : undefined : undefined) - .then(() => `Pipeline '${inputStartPipeline.name}' successfully started`) - .catch((error) => Promise.reject(`Failed to start Pipeline with error '${error}'`)) - ); - } } diff --git a/test/tekton/pipeline.test.ts b/test/tekton/pipeline.test.ts index 65473448..487149b1 100644 --- a/test/tekton/pipeline.test.ts +++ b/test/tekton/pipeline.test.ts @@ -33,6 +33,23 @@ suite('Tekton/Pipeline', () => { setup(() => { + sandbox.stub(vscode.workspace, 'getConfiguration').returns({ + get(): Promise { + return Promise.resolve(undefined); + }, + update(): Promise { + return Promise.resolve(); + }, + inspect(): { + key: string; + } { + return undefined; + }, + has(): boolean { + return true; + }, + start: true + }); execStub = sandbox.stub(TknImpl.prototype, 'execute').resolves({ error: null, stdout: '', stderr: '' }); showQuickPickStub = sandbox.stub(vscode.window, 'showQuickPick').resolves(undefined); sandbox.stub(TknImpl.prototype, 'getPipelines').resolves([pipelineItem]);