import fetch from 'node-fetch' ; import parseArgsStringToArgv from 'string-argv' ; import { ActionInputs } from "./args" ; export type OutputType = "Json" | "Toml" | "Stdout" | "Xml" | "Html" | "Lcov" ; export interface TarpaulinConfig { /**
     * Additional command line options.
     */ additionalOptions : string [ ] ; /**
     * The URL to download a tarball of cargo-tarpaulin from.
     */ downloadUrl : string ; /**
     * The type of tests to run. If {@code null}, doctests and normal tests
     * will be run.
     */ type : string | null ; /**
     * The maximum time a test can be ran without response before a timeout occurs.
     */ timeout : string | null ; /**
     * Output format of coverage report
     */ outType : OutputType ; } param input export default async function resolveConfig ( input ) { let releaseEndpoint = 'https://api.github.com/repos/xd009642/tarpaulin/releases' ; if ( process . env . GITHUB_RELEASE_ENDPOINT ) { releaseEndpoint = process . env . GITHUB_RELEASE_ENDPOINT ; } const downloadUrl = await getDownloadUrl ( releaseEndpoint , input . requestedVersion ) ; const type = input . runType ? input . runType : null ; const timeout = input . timeout ? input . timeout : null ; const outType = input . outType ? input . outType : "Xml" ; let additionalOptions = [ ] ; if ( input . opts !== null ) { additionalOptions = parseArgsStringToArgv ( input . opts ) ; } return { additionalOptions , downloadUrl , timeout , type , outType , } ; } param releaseEndpoint param requestedVersion async function getDownloadUrl ( releaseEndpoint , requestedVersion ) { const releaseInfoUri = requestedVersion === 'latest' ? `${ releaseEndpoint }/latest` : `${ releaseEndpoint }/tags/${ requestedVersion }` ; const releaseInfoRequest = await fetch ( releaseInfoUri ) ; const releaseInfo = await releaseInfoRequest . json ( ) ; const asset = releaseInfo [ "assets" ] . find ( asset => { return asset [ 'content_type' ] === 'application/gzip' ; } ) ; if ( ! asset ) { throw new Error ( `Couldn't find a release tarball containing binaries for ${ requestedVersion }` ) ; } return asset [ "browser_download_url" ] ; }