Skip to content

Commit

Permalink
show pipeline run diagram after starting pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
sudhirverma committed Jul 30, 2020
1 parent df94eb9 commit 9b03617
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 61 deletions.
26 changes: 12 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@
"default": "yaml",
"description": "Output format for Tekton specs. One of 'json' or 'yaml' (default)."
},
"vs-tekton.start": {
"Title": "Start Pipeline",
"type": "boolean",
"default": false,
"description": "Start pipeline from QuickPick"
},
"vs-tekton.pipelineRun": {
"Title": "Show PipelineRun on staring Pipeline",
"type": "boolean",
"default": true,
"description": "Show PipelineRun on staring Pipeline from webview"
},
"vs-tekton.showChannelOutput": {
"title": "Show channel on output",
"type": "boolean",
Expand Down Expand Up @@ -185,11 +197,6 @@
"category": "Tekton",
"enablement": "tekton:tkn"
},
{
"command": "tekton.pipeline.wizard.start",
"title": "Start Wizard",
"category": "Tekton"
},
{
"command": "tekton.explorerView.delete",
"title": "Delete",
Expand Down Expand Up @@ -488,10 +495,6 @@
"command": "tekton.pipeline.start",
"when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/"
},
{
"command": "tekton.pipeline.wizard.start",
"when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/"
},
{
"command": "tekton.openInEditor",
"when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/"
Expand Down Expand Up @@ -614,11 +617,6 @@
"when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == pipeline",
"group": "c1@2"
},
{
"command": "tekton.pipeline.wizard.start",
"when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == pipeline",
"group": "c1@3"
},
{
"command": "tekton.pipeline.list",
"when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == pipelinenode",
Expand Down
12 changes: 2 additions & 10 deletions src/pipeline/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as path from 'path';
import { Disposable } from '../util/disposable';
import { debounce } from 'debounce';
import { TknResourceItem } from '../tekton/webviewstartpipeline';
import { Progress } from '../util/progress';
import { TektonItem } from '../tekton/tektonitem';

export interface PipelineWizardInput {
Expand Down Expand Up @@ -40,7 +39,6 @@ export class PipelineWizard extends Disposable {
private readonly onDidChangeViewStateEmitter = new vscode.EventEmitter<vscode.WebviewPanelOnDidChangeViewStateEvent>();
public readonly onDidChangeViewState = this.onDidChangeViewStateEmitter.event;


constructor(webview: vscode.WebviewPanel, private input: PipelineWizardInput) {
super();
this.editor = webview;
Expand All @@ -49,22 +47,16 @@ export class PipelineWizard extends Disposable {
}));


this.register(this.editor.webview.onDidReceiveMessage(e => {
this.register(this.editor.webview.onDidReceiveMessage(async e => {
switch (e.type) {
case 'startPipeline':
// eslint-disable-next-line no-case-declarations
const inputStartPipeline = e.body;
this.dispose();
return Progress.execFunctionWithProgress(`Starting Pipeline '${inputStartPipeline.name}'.`, () =>
TektonItem.tkn.startPipeline(inputStartPipeline)
.then(() => TektonItem.explorer.refresh())
.then(() => `Pipeline '${inputStartPipeline.name}' successfully started`)
.catch((error) => Promise.reject(`Failed to start Pipeline with error '${error}'`))
);
return await TektonItem.startPipeline(inputStartPipeline);
}
}));


this.updateFunc();
}

Expand Down
62 changes: 28 additions & 34 deletions src/tekton/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,35 @@ import { pipelineData } from './webviewstartpipeline';
export class Pipeline extends TektonItem {

static async start(pipeline: TektonNode): Promise<string> {
if (!pipeline) {
pipeline = await window.showQuickPick(await Pipeline.getPipelineNames(), { placeHolder: 'Select Pipeline to start', ignoreFocusOut: true });
}
if (!pipeline) return null;
const result: cliInstance.CliExitData = await Pipeline.tkn.execute(Command.listPipelines(), process.cwd(), false);
let data: TknPipelineTrigger[] = [];
if (result.error) {
console.log(result + ' Std.err when processing pipelines');
}
try {
data = JSON.parse(result.stdout).items;
} catch (ignore) {
//show no pipelines if output is not correct json
}
if (Pipeline.startQuickPick()) {
if (!pipeline) {
pipeline = await window.showQuickPick(await Pipeline.getPipelineNames(), { placeHolder: 'Select Pipeline to start', ignoreFocusOut: true });
}
if (!pipeline) return null;
const result: cliInstance.CliExitData = await Pipeline.tkn.execute(Command.listPipelines(), process.cwd(), false);
let data: TknPipelineTrigger[] = [];
if (result.error) {
console.log(result + ' Std.err when processing pipelines');
}
try {
data = JSON.parse(result.stdout).items;
} catch (ignore) {
//show no pipelines if output is not correct json
}

const pipelineTrigger = data.map<Trigger>(value => ({
name: value.metadata.name,
resources: value.spec.resources,
params: value.spec.params ? value.spec.params : undefined,
workspaces: value.spec['workspaces'] ? value.spec['workspaces'] : undefined,
serviceAcct: value.spec.serviceAccount ? value.spec.serviceAccount : undefined
})).filter((obj) => obj.name === pipeline.getName());
const inputStartPipeline = await PipelineContent.startObject(pipelineTrigger, 'Pipeline');
const pipelineTrigger = data.map<Trigger>(value => ({
name: value.metadata.name,
resources: value.spec.resources,
params: value.spec.params ? value.spec.params : undefined,
workspaces: value.spec['workspaces'] ? value.spec['workspaces'] : undefined,
serviceAcct: value.spec.serviceAccount ? value.spec.serviceAccount : undefined
})).filter((obj) => obj.name === pipeline.getName());
const inputStartPipeline = await PipelineContent.startObject(pipelineTrigger, 'Pipeline');

return Progress.execFunctionWithProgress(`Starting Pipeline '${inputStartPipeline.name}'.`, () =>
Pipeline.tkn.startPipeline(inputStartPipeline)
.then(() => Pipeline.explorer.refresh())
.then(() => `Pipeline '${inputStartPipeline.name}' successfully started`)
.catch((error) => Promise.reject(`Failed to start Pipeline with error '${error}'`))
);
return await Pipeline.startPipeline(inputStartPipeline);
} else {
Pipeline.startWizard(pipeline);
}
}

static async restart(pipeline: TektonNode): Promise<string> {
Expand Down Expand Up @@ -109,12 +108,7 @@ export class Pipeline extends TektonItem {
}
const trigger = await pipelineData(data);
if (!trigger.workspaces && !trigger.resources && !trigger.params) {
Progress.execFunctionWithProgress(`Starting Pipeline '${trigger.name}'.`, () =>
TektonItem.tkn.startPipeline(trigger)
.then(() => TektonItem.explorer.refresh())
.then(() => `Pipeline '${trigger.name}' successfully started`)
.catch((error) => Promise.reject(`Failed to start Pipeline with error '${error}'`))
);
await Pipeline.startPipeline(trigger);
} else {
PipelineWizard.create({ trigger, resourceColumn: ViewColumn.Active }, ViewColumn.Active);
}
Expand Down
27 changes: 27 additions & 0 deletions src/tekton/tektonitem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ 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.',
Expand Down Expand Up @@ -126,4 +130,27 @@ export abstract class TektonItem {
static getOutputFormat(): string {
return workspace.getConfiguration('vs-tekton')['outputFormat'];
}

static startQuickPick(): boolean {
return workspace
.getConfiguration('vs-tekton')
.get<boolean>('start');
}

static ShowPipelineRun(): boolean {
return workspace
.getConfiguration('vs-tekton')
.get<boolean>('pipelineRun');
}

static startPipeline(inputStartPipeline: StartObject): Promise<string> {
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}'`))
);
}
}
7 changes: 4 additions & 3 deletions src/tkn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ export interface Tkn {
getPipelineRunsList(pipelineRun?: TektonNode): Promise<TektonNode[]>;
getTaskRunList(taskRun?: TektonNode): Promise<TektonNode[]>;
getRawPipelineRun(name: string): Promise<PipelineRunData | undefined>;
_getPipelineRuns(pipeline: TektonNode, pipelineName?: string): Promise<TektonNode[]> | undefined;
clearCache?(): void;
}

Expand Down Expand Up @@ -1048,11 +1049,11 @@ export class TknImpl implements Tkn {
return this.limitView(pipeline, pipelineRuns);
}

async _getPipelineRuns(pipeline: TektonNode): Promise<TektonNode[]> | undefined {
const result = await this.execute(Command.listPipelineRuns(pipeline.getName()));
async _getPipelineRuns(pipeline: TektonNode, pipelineName?: string): Promise<TektonNode[]> | undefined {
const result = await this.execute(Command.listPipelineRuns(pipelineName ?? pipeline.getName()));
if (result.error) {
console.log(result + ' Std.err when processing pipelines');
return [new TektonNodeImpl(pipeline, getStderrString(result.error), ContextType.PIPELINERUN, this, TreeItemCollapsibleState.None)];
if (!pipelineName) return [new TektonNodeImpl(pipeline, getStderrString(result.error), ContextType.PIPELINERUN, this, TreeItemCollapsibleState.None)];
}

let data: PipelineRunData[] = [];
Expand Down

0 comments on commit 9b03617

Please sign in to comment.