import * as e from 'fp-ts/lib/Either' ; import * as t from 'io-ts' ; import { Octokit } from 'probot' ; import yaml from 'js-yaml' ; import { Sources } from './sources' ; const StarterConfiguration = t . intersection ( [ t . type ( { name : t . string , path : t . string , } ) , t . partial ( { description : t . string , } ) , ] ) ; export interface StarterConfiguration extends t . TypeOf < typeof StarterConfiguration > { } const Configuration = t . type ( { starters : t . array ( StarterConfiguration ) , } ) ; export interface EmmaConfiguration extends t . TypeOf < typeof Configuration > { } param config function decodeConfiguration ( config ) { return Configuration . decode ( config ) ; } param ctx export const getConfig = ( sources ) => async ( github , owner , repo ) : Promise < EmmaConfiguration | null > => { try { const res = await github . repos . getContents ( { owner : owner , repo : repo , path : sources . constants . configurationFilePath , } ) ; if ( Array . isArray ( res . data ) || ! res . data . content ) { return null ; } const buffer = Buffer . from ( res . data . content , 'base64' ) . toString ( ) ; const yml = yaml . safeLoad ( buffer ) ; const config = decodeConfiguration ( yml ) ; if ( e . isLeft ( config ) ) { return null ; } return config . right ; } catch ( err ) { return null ; } } ;