Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display PipelineRun result as notifications #475

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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