import fs from 'fs' ; import fetch from 'node-fetch' ; import * as core from '@actions/core' ; /**
 * Checks connection with Maven Central, throws error if unable to connect.
 */ export async function mavenCentral ( ) { const response = await fetch ( 'https://repo1.maven.org/maven2/' ) ; if ( ! response . ok ) { throw new Error ( 'Unable to connect to Maven Central' ) ; } core . info ( '✓ Connected to Maven Central' ) ; } returns { string } export function githubToken ( ) { const token = core . getInput ( 'github-token' ) ; if ( token === '' ) { throw new Error ( 'You need to provide a Github token in the `github-token` input' ) ; } core . info ( '✓ Github Token provided as input' ) ; return token ; } const defaultRepoConfLocation = '.github/.scala-steward.conf' ; returns { string | undefined } export function defaultRepoConf ( ) { const path = core . getInput ( 'default-repo-conf' ) ; const fileExists = fs . existsSync ( path ) ; if ( ! fileExists && path !== defaultRepoConfLocation ) { throw new Error ( `Provided default repo conf file (${ path }) does not exist` ) ; } if ( fileExists ) { core . info ( `✓ Default Scala Steward configuration set to: ${ path }` ) ; return path ; } return undefined ; } returns { string } export function githubRepository ( ) { const repo = core . getInput ( 'github-repository' ) || process . env . GITHUB_REPOSITORY ; if ( repo === undefined ) { throw new Error ( 'Unable to read Github repository from `github-repository` ' + 'input or `GITHUB_REPOSITORY` environment variable' ) ; } const branches = core . getInput ( 'branches' ) . split ( ',' ) . filter ( string => string ) ; if ( branches . length === 1 ) { const branch = branches [ 0 ] ; core . info ( `✓ Github Repository set to: ${ repo }. Will update ${ branch } branch.` ) ; return `- ${ repo }:${ branch }` ; } if ( branches . length > 1 ) { core . info ( `✓ Github Repository set to: ${ repo }. Will update ${ branches . join ( ', ' ) } branches.` ) ; return branches . map ( ( branch ) => `- ${ repo }:${ branch }` ) . join ( '\n' ) ; } core . info ( `✓ Github Repository set to: ${ repo }.` ) ; return `- ${ repo }` ; } returns { string | undefined } export function reposFile ( ) { const file = core . getInput ( 'repos-file' ) ; if ( ! file ) { return undefined ; } if ( fs . existsSync ( file ) ) { core . info ( `✓ Using multiple repos file: ${ file }` ) ; return fs . readFileSync ( file ) ; } throw new Error ( `The path indicated in \`repos-file\` (${ file }) does not exist` ) ; } returns { { id : string , keyFile : string } | undefined } export function githubAppInfo ( ) { const id = core . getInput ( 'github-app-id' ) ; const key = core . getInput ( 'github-app-key' ) ; if ( ! id && ! key ) { return undefined ; } if ( id && key ) { const keyFile = `${ fs . mkdtempSync ( 'tmp-' ) }/github-app-private-key.pem` ; fs . writeFileSync ( keyFile , key ) ; core . info ( `✓ Github App ID: ${ id }` ) ; core . info ( `✓ Github App private key is written to: ${ keyFile }` ) ; return { id , keyFile } ; } throw new Error ( '`github-app-id` and `github-app-key` inputs have to be set together. One of them is missing' ) ; }