import { HttpClient } from '@angular/common/http' ; import { Injectable } from '@angular/core' ; import { Strings } from './strings' ; @ Injectable ( ) export class GitHubApi { constructor ( private httpClient ) { } public async getLatestReleaseAsync ( owner , repo , includePrereleases ) { const url = `https://api.github.com/repos/${ owner }/${ repo }/releases` ; const releasesResponse = await this . httpClient . get < any > ( url ) . toPromise ( ) ; let latestRelease = releasesResponse . find ( ( x ) => x . prerelease ) ; if ( includePrereleases ) { latestRelease = releasesResponse . find ( ( x ) => x . prerelease ) ; } else { latestRelease = releasesResponse . find ( ( x ) => ! x . prerelease ) ; } if ( latestRelease != undefined && latestRelease . tag_name != undefined ) { return Strings . replaceFirst ( latestRelease . tag_name , 'v' , '' ) ; } return '' ; } }