Skip to content

Commit

Permalink
Display PipelineRun result as notifications (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudhirverma authored Dec 14, 2020
1 parent eb2b314 commit 45276d1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/tekton.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface TknTaskRunSpec {


export interface TknTaskRun {
kind?: string;
metadata: ObjectMetadata;
spec: TknTaskRunSpec;
status?: {
Expand Down
3 changes: 2 additions & 1 deletion src/tekton/startpipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';



Expand All @@ -16,6 +17,6 @@ export function startPipeline(inputStartPipeline: StartObject): Promise<string>
.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}'`))
);
}
21 changes: 21 additions & 0 deletions src/util/watchResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, boolean>();
const kubeConfigFolder: string = path.join(Platform.getUserHomePath(), '.kube');

export enum ResourceType {
pipelineRun = 'PipelineRun'
}

function checkPipelineRunNotifications(): boolean {
return workspace
.getConfiguration('vs-tekton')
.get<boolean>('pipelineRunNotifications');
}

export class WatchResources {

public fsw: FileContentChangeNotifier;
Expand All @@ -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;
Expand Down

0 comments on commit 45276d1

Please sign in to comment.