From f8f559223a80ffb8f80ecc8cb6131ea0ded0800a Mon Sep 17 00:00:00 2001 From: Sudhir Verma Date: Fri, 11 Dec 2020 15:11:51 +0530 Subject: [PATCH] Display PipelineRun result as notifications --- package.json | 6 ++++++ src/tekton.d.ts | 1 + src/tekton/startpipeline.ts | 3 ++- src/util/watchResources.ts | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 9f1035b1..3b5c4e0e 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,12 @@ "default": false, "description": "Start pipeline from Command Palette." }, + "vs-tekton.pipelineRunNotifications": { + "Title": "Show pipelineRun notification", + "type": "boolean", + "default": true, + "description": "Show pipelineRun execution status in notification." + }, "vs-tekton.pipelineRun": { "Title": "Show PipelineRun on staring Pipeline", "type": "boolean", diff --git a/src/tekton.d.ts b/src/tekton.d.ts index 73dcd23b..92bca956 100644 --- a/src/tekton.d.ts +++ b/src/tekton.d.ts @@ -15,6 +15,7 @@ interface TknTaskRunSpec { export interface TknTaskRun { + kind?: string; metadata: ObjectMetadata; spec: TknTaskRunSpec; status?: { diff --git a/src/tekton/startpipeline.ts b/src/tekton/startpipeline.ts index f2a61b96..5ced34c8 100644 --- a/src/tekton/startpipeline.ts +++ b/src/tekton/startpipeline.ts @@ -7,6 +7,7 @@ import { StartObject } from './pipelinecontent'; import { Progress } from '../util/progress'; import { TektonItem } from './tektonitem'; import { showPipelineRunPreview } from '../pipeline/pipeline-preview'; +import { window } from 'vscode'; @@ -16,6 +17,6 @@ export function startPipeline(inputStartPipeline: StartObject): Promise .then((pipelineRunName) => TektonItem.ShowPipelineRun() ? showPipelineRunPreview(pipelineRunName) : undefined) .then(() => TektonItem.explorer.refresh()) .then(() => `Pipeline '${inputStartPipeline.name}' successfully started`) - .catch((error) => Promise.reject(`Failed to start Pipeline with error '${error}'`)) + .catch((error) => window.showErrorMessage(`Failed to start Pipeline with error '${error}'`)) ); } diff --git a/src/util/watchResources.ts b/src/util/watchResources.ts index 5d42396a..9227f98e 100644 --- a/src/util/watchResources.ts +++ b/src/util/watchResources.ts @@ -8,10 +8,22 @@ import { Platform } from './platform'; import { kubectl, KubectlCommands } from '../kubectl'; import { pipelineExplorer } from '../pipeline/pipelineExplorer'; import { FileContentChangeNotifier, WatchUtil } from './watch'; +import { window, workspace } from 'vscode'; +import { humanizer } from '../tkn'; export const pipelineTriggerStatus = new Map(); const kubeConfigFolder: string = path.join(Platform.getUserHomePath(), '.kube'); +export enum ResourceType { + pipelineRun = 'PipelineRun' +} + +function checkPipelineRunNotifications(): boolean { + return workspace + .getConfiguration('vs-tekton') + .get('pipelineRunNotifications'); +} + export class WatchResources { public fsw: FileContentChangeNotifier; @@ -32,6 +44,15 @@ export class WatchResources { if (id !== run.metadata.uid) { pipelineExplorer.refresh(); } else if (run.status?.completionTime !== undefined) { + if (checkPipelineRunNotifications()) { + if (run.kind === ResourceType.pipelineRun) { + if (run.status.conditions[0].status === 'True') { + window.showInformationMessage(`PipelineRun: ${run.metadata.name} is successfully completed. Duration to complete the execution 'Time: ${humanizer(Date.parse(run.status.completionTime) - Date.parse(run.status.startTime))}'`); + } else if (run.status.conditions[0].status === 'False') { + window.showErrorMessage(`PipelineRun: ${run.metadata.name} fails. Reason: ${run.status.conditions[0].reason} and Message: ${run.status.conditions[0].message}`); + } + } + } pipelineExplorer.refresh(); } id = run.metadata.uid;