Some checks failed
charlyghislain/charlyghislaindotcom/pipeline/head There was a failure building this commit
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import {Component, OnInit} from '@angular/core';
|
|
import {BuildInfoService} from './build-info.service';
|
|
import {Observable, of} from 'rxjs';
|
|
import {catchError, defaultIfEmpty, filter, map, publishReplay, refCount} from 'rxjs/operators';
|
|
import {BuildInfo} from './build-info';
|
|
import {DateTime} from 'luxon';
|
|
|
|
@Component({
|
|
selector: 'app-root',
|
|
templateUrl: './app.component.html',
|
|
styleUrls: ['./app.component.scss'],
|
|
})
|
|
export class AppComponent implements OnInit {
|
|
|
|
buildDate: Observable<string>;
|
|
buildCommit: Observable<string>;
|
|
|
|
constructor(private buildinfoService: BuildInfoService) {
|
|
const buildInfo = this.buildinfoService.getBuildInfo()
|
|
.pipe(
|
|
catchError(e => of(<BuildInfo>{date: null, commit: null})),
|
|
publishReplay(1), refCount(),
|
|
);
|
|
this.buildDate = buildInfo.pipe(
|
|
map(info => info.date),
|
|
map(date => this.parseDate(date)),
|
|
);
|
|
this.buildCommit = buildInfo.pipe(
|
|
map(info => info.commit),
|
|
filter(commit => commit != null),
|
|
defaultIfEmpty('HEAD'),
|
|
);
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
}
|
|
|
|
private parseDate(dateString: string) {
|
|
const parsedDateString = dateString == null ? undefined : DateTime.fromISO(dateString).toISODate();
|
|
return parsedDateString;
|
|
}
|
|
}
|