import { Repo , User } from "github-types" ; import { Observable , defaultIfEmpty , map , zip } from "rxjs" ; import { requestJSON } from "~/browser" ; import { SourceFacts } from "../_" ; /**
 * GitHub release (partial)
 */ interface Release { tag_name : string ; } param user param repo returns export function fetchSourceFactsFromGitHub ( user , repo ? ) { if ( typeof repo !== "undefined" ) { const url = `https://api.github.com/repos/${ user }/${ repo }` ; return zip ( requestJSON < Release > ( `${ url }/releases/latest` ) . pipe ( map ( release => ( { version : release . tag_name } ) ) , defaultIfEmpty ( { } ) ) , requestJSON < Repo > ( url ) . pipe ( map ( info => ( { stars : info . stargazers_count , forks : info . forks_count } ) ) , defaultIfEmpty ( { } ) ) ) . pipe ( map ( ( [ release , info ] ) => ( { ... release , ... info } ) ) ) ; } else { const url = `https://api.github.com/users/${ user }` ; return requestJSON < User > ( url ) . pipe ( map ( info => ( { repositories : info . public_repos } ) ) , defaultIfEmpty ( { } ) ) ; } }