Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
#3668 improved version check (#3797)
Browse files Browse the repository at this point in the history
* #3668 improved version check

Signed-off-by: Klaus Strießnig <k.striessnig@gmail.com>

* updated version check information text in user panel

Signed-off-by: Klaus Strießnig <k.striessnig@gmail.com>
  • Loading branch information
Kirdock committed Apr 21, 2021
1 parent 263c880 commit b167666
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 43 deletions.
12 changes: 9 additions & 3 deletions bridge/client/app/_services/api.service.ts
Expand Up @@ -16,6 +16,7 @@ import {KeptnService} from '../_models/keptn-service';
import {KeptnServicesMock} from '../_models/keptn-services.mock';
import {TaskNames} from '../_models/task-names.mock';
import {Deployment} from '../_models/deployment';
import * as moment from 'moment';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -60,12 +61,17 @@ export class ApiService {
.get<any>(url, { responseType: 'text' as 'json' });
}

public isVersionCheckEnabled(): boolean {
return JSON.parse(localStorage.getItem(this.VERSION_CHECK_COOKIE));
public isVersionCheckEnabled(): boolean | undefined {
const versionInfo = JSON.parse(localStorage.getItem(this.VERSION_CHECK_COOKIE));
let enabled = typeof versionInfo === 'boolean' ? versionInfo : versionInfo?.enabled; // support old format
if (!enabled && (!versionInfo?.time || moment().subtract(5, 'days').isAfter(versionInfo.time))) {
enabled = undefined;
}
return enabled;
}

public setVersionCheck(enabled: boolean): void {
localStorage.setItem(this.VERSION_CHECK_COOKIE, String(enabled));
localStorage.setItem(this.VERSION_CHECK_COOKIE, JSON.stringify({enabled, time: moment().valueOf()}));
}

public getAvailableVersions(): Observable<any> {
Expand Down
10 changes: 5 additions & 5 deletions bridge/client/app/app-header/app-header.component.html
Expand Up @@ -37,7 +37,7 @@ <h3 class="m-0">Get started</h3>
</div>
</div>
<hr/>
<div class="mt-2 mb-3" fxLayout="row" fxLayoutAlign="flex-start center" *ngIf="keptnInfo?.bridgeInfo?.enableVersionCheckFeature && !keptnInfo?.versionCheckEnabled">
<div class="mt-2 mb-3" fxLayout="row" fxLayoutAlign="flex-start center" *ngIf="keptnInfo?.bridgeInfo?.enableVersionCheckFeature && keptnInfo?.versionCheckEnabled === false">
<dt-icon class="error" [name]="'criticalevent'"></dt-icon>
<p class="small m-0">Automatic version and security check disabled</p>
</div>
Expand All @@ -59,19 +59,19 @@ <h3 class="m-0">Get started</h3>
<p class="m-0">Version check</p>
</div>
<div>
<dt-switch (change)="versionCheckClicked($event)" [checked]="keptnInfo?.versionCheckEnabled"></dt-switch>
<dt-switch (change)="versionCheckClicked($event)" [checked]="keptnInfo?.versionCheckEnabled !== false"></dt-switch>
</div>
</div>
<p class="m-0 mt-2 small">By enabling this feature, Keptn will collect statistical data and notify about new version and security patches for Keptn and Keptn Bridge. Details can be found at <a [href]="versionCheckReference | keptnUrl" target="_blank" [textContent]="versionCheckReference | keptnUrl"></a></p>
<p class="m-0 mt-2 small">By enabling this feature (recommended), Keptn will notify about new versions and security patches for Keptn and therefore collect statistical data. Details can be found at <a [href]="versionCheckReference | keptnUrl" target="_blank" [textContent]="versionCheckReference | keptnUrl"></a></p>
</div>
</dt-context-dialog>

<dt-confirmation-dialog [state]="versionCheckDialogState" aria-label="Version check feature info">
<dt-confirmation-dialog-state name="info">
As of now you can enable automatic version check to be notified about new version and security patches for Keptn and Keptn Bridge. This setting can be changed in the user menu on the top right.
Keptn provides an automatic version check to be notified about new versions and security patches for Keptn. It is recommended to have this check enabled. This setting can be changed in the user menu on the top right.
<dt-confirmation-dialog-actions>
<button dt-button (click)="acceptVersionCheck(true)">Accept (recommended)</button>
<button dt-button variant="secondary" (click)="acceptVersionCheck(false)">Decline</button>
<button dt-button (click)="acceptVersionCheck(true)">Accept</button>
</dt-confirmation-dialog-actions>
</dt-confirmation-dialog-state>
<dt-confirmation-dialog-state name="success">
Expand Down
61 changes: 26 additions & 35 deletions bridge/client/app/app-header/app-header.component.ts
@@ -1,15 +1,14 @@
import semver from 'semver';

import {Component, OnDestroy, OnInit} from '@angular/core';
import {Router, RoutesRecognized} from "@angular/router";
import {Observable, Subject, Subscription} from "rxjs";
import {filter, map, takeUntil} from "rxjs/operators";
import {ActivatedRoute} from '@angular/router';
import {Observable, Subject} from 'rxjs';
import {filter, takeUntil} from 'rxjs/operators';

import {Project} from "../_models/project";
import {DataService} from "../_services/data.service";
import {ApiService} from "../_services/api.service";
import {NotificationsService} from "../_services/notifications.service";
import {NotificationType} from "../_models/notification";
import {Project} from '../_models/project';
import {DataService} from '../_services/data.service';
import {NotificationsService} from '../_services/notifications.service';
import {NotificationType} from '../_models/notification';

@Component({
selector: 'app-header',
Expand All @@ -25,37 +24,29 @@ export class AppHeaderComponent implements OnInit, OnDestroy {

public keptnInfo: any;
public versionCheckDialogState: string | null;
public versionCheckReference = "/reference/version_check/";
public versionCheckReference = '/reference/version_check/';

constructor(private router: Router, private dataService: DataService, private apiService: ApiService, private notificationsService: NotificationsService) { }
constructor(private route: ActivatedRoute, private dataService: DataService, private notificationsService: NotificationsService) { }

ngOnInit() {
this.projects = this.dataService.projects;

this.router.events
this.route.params
.pipe(takeUntil(this.unsubscribe$))
.subscribe(event => {
if(event instanceof RoutesRecognized) {
let projectName = event.state.root.children[0].params['projectName'];
this.project = this.dataService.projects.pipe(
filter(projects => !!projects),
map(projects => projects.find(p => {
return p.projectName === projectName;
}))
);
}
.subscribe(params => {
this.project = this.dataService.getProject(params.projectName);
});

this.dataService.keptnInfo
.pipe(filter(keptnInfo => !!keptnInfo))
.pipe(takeUntil(this.unsubscribe$))
.subscribe(keptnInfo => {
this.keptnInfo = keptnInfo;
if(keptnInfo.versionCheckEnabled === null) {
if (keptnInfo.versionCheckEnabled === undefined) {
this.showVersionCheckInfoDialog();
} else if(keptnInfo.versionCheckEnabled) {
keptnInfo.keptnVersionInvalid = !this.doVersionCheck(keptnInfo.keptnVersion, keptnInfo.availableVersions.cli.stable, keptnInfo.availableVersions.cli.prerelease, "Keptn");
keptnInfo.bridgeVersionInvalid = !this.doVersionCheck(keptnInfo.bridgeInfo.bridgeVersion, keptnInfo.availableVersions.bridge.stable, keptnInfo.availableVersions.bridge.prerelease, "Keptn Bridge");;
} else if (keptnInfo.versionCheckEnabled) {
keptnInfo.keptnVersionInvalid = !this.doVersionCheck(keptnInfo.keptnVersion, keptnInfo.availableVersions.cli.stable, keptnInfo.availableVersions.cli.prerelease, 'Keptn');
keptnInfo.bridgeVersionInvalid = !this.doVersionCheck(keptnInfo.bridgeInfo.bridgeVersion, keptnInfo.availableVersions.bridge.stable, keptnInfo.availableVersions.bridge.prerelease, 'Keptn Bridge');;
}
});
}
Expand All @@ -65,9 +56,9 @@ export class AppHeaderComponent implements OnInit, OnDestroy {
return false;

stableVersions.forEach(stableVersion => {
if(semver.lt(currentVersion, stableVersion)) {
if (semver.lt(currentVersion, stableVersion)) {
let genMessage;
switch(semver.diff(currentVersion, stableVersion)) {
switch (semver.diff(currentVersion, stableVersion)) {
case 'patch':
genMessage = (version, type, major, minor) => `New ${type} ${version} available. This is a patch version with bug fixes and minor improvements. For details how to upgrade visit https://keptn.sh/docs/${major}.${minor}.x/operate/upgrade/`;
break;
Expand All @@ -81,16 +72,16 @@ export class AppHeaderComponent implements OnInit, OnDestroy {
genMessage = (version, type, major, minor) => `New ${type} ${version} available. It might contain incompatible changes. For details how to upgrade visit https://keptn.sh/docs/${major}.${minor}.x/operate/upgrade/`;
}

let major = semver.major(stableVersion);
let minor = semver.minor(stableVersion);
const major = semver.major(stableVersion);
const minor = semver.minor(stableVersion);
this.notificationsService.addNotification(NotificationType.Info, genMessage(stableVersion, type, major, minor));
}
});
prereleaseVersions.forEach(prereleaseVersion => {
if(semver.lt(currentVersion, prereleaseVersion)) {
let genMessage = (version, type, major, minor) => `New ${type} ${version} available. This is a pre-release version with experimental features. For details how to upgrade visit: https://keptn.sh/docs/${major}.${minor}.x/operate/upgrade/`;
let major = semver.major(prereleaseVersion);
let minor = semver.minor(prereleaseVersion);
if (semver.lt(currentVersion, prereleaseVersion)) {
const genMessage = (version, type, major, minor) => `New ${type} ${version} available. This is a pre-release version with experimental features. For details how to upgrade visit: https://keptn.sh/docs/${major}.${minor}.x/operate/upgrade/`;
const major = semver.major(prereleaseVersion);
const minor = semver.minor(prereleaseVersion);
this.notificationsService.addNotification(NotificationType.Info, genMessage(prereleaseVersion, type, major, minor));
}
});
Expand All @@ -99,13 +90,13 @@ export class AppHeaderComponent implements OnInit, OnDestroy {
}

showVersionCheckInfoDialog() {
if(this.keptnInfo.bridgeInfo.enableVersionCheckFeature)
if (this.keptnInfo.bridgeInfo.enableVersionCheckFeature)
this.versionCheckDialogState = 'info';
}

acceptVersionCheck(accepted: boolean): void {
this.dataService.setVersionCheck(accepted);
if(accepted)
if (accepted)
this.versionCheckDialogState = 'success';

setTimeout(() => {
Expand Down

0 comments on commit b167666

Please sign in to comment.