diff --git a/__tests__/helpers/get-git-mock.ts b/__tests__/helpers/get-git-mock.ts index 6c1ecb9e1..8281c17fd 100644 --- a/__tests__/helpers/get-git-mock.ts +++ b/__tests__/helpers/get-git-mock.ts @@ -19,6 +19,11 @@ export default function getGitRemoteMock( } // second call (used to grab default branch) if (arr.length === 2 && arr[0] === 'show' && arr[1] === remote) { + if (remote === 'bad-remote') { + return Promise.reject( + new Error(`fatal: unable to access '${remoteUrl}': Could not resolve host: ${remoteUrl}`) + ) as unknown as Response; + } if (!defaultBranch) return Promise.reject(new Error('Bad mock uh oh')) as unknown as Response; return Promise.resolve(`* remote origin Fetch URL: ${remoteUrl} diff --git a/__tests__/lib/__snapshots__/createGHA.test.ts.snap b/__tests__/lib/__snapshots__/createGHA.test.ts.snap index 05cd6cf45..23b96d8a0 100644 --- a/__tests__/lib/__snapshots__/createGHA.test.ts.snap +++ b/__tests__/lib/__snapshots__/createGHA.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`#createGHA command inputs changelogs should run GHA creation workflow and generate valid workflow file 1`] = ` +exports[`#createGHA command inputs changelogs (single) should run GHA creation workflow and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! āœØ @@ -14,7 +14,7 @@ Almost done! Just a couple more steps: " `; -exports[`#createGHA command inputs changelogs should run GHA creation workflow and generate valid workflow file 2`] = ` +exports[`#createGHA command inputs changelogs (single) should run GHA creation workflow and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action šŸ¦‰ @@ -37,16 +37,16 @@ jobs: - name: Run \`changelogs\` command šŸš€ uses: readmeio/rdme@v7 with: - rdme: changelogs ./changelogs --key=\${{ secrets.README_API_KEY }} + rdme: changelogs ./changelogs/rdme.md --key=\${{ secrets.README_API_KEY }} " `; -exports[`#createGHA command inputs changelogs should run GHA creation workflow and generate valid workflow file 3`] = ` +exports[`#createGHA command inputs changelogs (single) should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! āœØ Almost done! Just a couple more steps: -1. Push your newly created file (.github/workflows/rdme-changelogs.yml) to GitHub šŸš€ +1. Push your newly created file (.github/workflows/rdme-changelogs-with-github-flag.yml) to GitHub šŸš€ 2. Create a GitHub secret called README_API_KEY and populate the value with your ReadMe API key (ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢I_KEY) šŸ”‘ šŸ” Check out GitHub's docs for more info on creating encrypted secrets (https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) @@ -55,7 +55,7 @@ Almost done! Just a couple more steps: " `; -exports[`#createGHA command inputs changelogs should run GHA creation workflow and generate valid workflow file 4`] = ` +exports[`#createGHA command inputs changelogs (single) should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action šŸ¦‰ @@ -63,10 +63,10 @@ name: ReadMe GitHub Action šŸ¦‰ on: push: branches: - # This workflow will run every time you push code to the following branch: \`some-branch\` + # This workflow will run every time you push code to the following branch: \`another-branch\` # Check out GitHub's docs for more info on configuring this: # https://docs.github.com/actions/using-workflows/events-that-trigger-workflows - - some-branch + - another-branch jobs: rdme-changelogs: @@ -82,12 +82,12 @@ jobs: " `; -exports[`#createGHA command inputs changelogs should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 1`] = ` +exports[`#createGHA command inputs changelogs should run GHA creation workflow and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! āœØ Almost done! Just a couple more steps: -1. Push your newly created file (.github/workflows/rdme-changelogs-with-github-flag.yml) to GitHub šŸš€ +1. Push your newly created file (.github/workflows/rdme-changelogs.yml) to GitHub šŸš€ 2. Create a GitHub secret called README_API_KEY and populate the value with your ReadMe API key (ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢I_KEY) šŸ”‘ šŸ” Check out GitHub's docs for more info on creating encrypted secrets (https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) @@ -96,7 +96,7 @@ Almost done! Just a couple more steps: " `; -exports[`#createGHA command inputs changelogs should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 2`] = ` +exports[`#createGHA command inputs changelogs should run GHA creation workflow and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action šŸ¦‰ @@ -104,10 +104,10 @@ name: ReadMe GitHub Action šŸ¦‰ on: push: branches: - # This workflow will run every time you push code to the following branch: \`another-branch\` + # This workflow will run every time you push code to the following branch: \`some-branch\` # Check out GitHub's docs for more info on configuring this: # https://docs.github.com/actions/using-workflows/events-that-trigger-workflows - - another-branch + - some-branch jobs: rdme-changelogs: @@ -123,7 +123,7 @@ jobs: " `; -exports[`#createGHA command inputs changelogs should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 3`] = ` +exports[`#createGHA command inputs changelogs should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! āœØ @@ -137,7 +137,7 @@ Almost done! Just a couple more steps: " `; -exports[`#createGHA command inputs changelogs should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 4`] = ` +exports[`#createGHA command inputs changelogs should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action šŸ¦‰ @@ -160,11 +160,11 @@ jobs: - name: Run \`changelogs\` command šŸš€ uses: readmeio/rdme@v7 with: - rdme: changelogs ./changelogs/rdme.md --key=\${{ secrets.README_API_KEY }} + rdme: changelogs ./changelogs --key=\${{ secrets.README_API_KEY }} " `; -exports[`#createGHA command inputs custompages should run GHA creation workflow and generate valid workflow file 1`] = ` +exports[`#createGHA command inputs custompages (single) should run GHA creation workflow and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! āœØ @@ -178,7 +178,7 @@ Almost done! Just a couple more steps: " `; -exports[`#createGHA command inputs custompages should run GHA creation workflow and generate valid workflow file 2`] = ` +exports[`#createGHA command inputs custompages (single) should run GHA creation workflow and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action šŸ¦‰ @@ -201,16 +201,16 @@ jobs: - name: Run \`custompages\` command šŸš€ uses: readmeio/rdme@v7 with: - rdme: custompages ./custompages --key=\${{ secrets.README_API_KEY }} + rdme: custompages ./custompages/rdme.md --key=\${{ secrets.README_API_KEY }} " `; -exports[`#createGHA command inputs custompages should run GHA creation workflow and generate valid workflow file 3`] = ` +exports[`#createGHA command inputs custompages (single) should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! āœØ Almost done! Just a couple more steps: -1. Push your newly created file (.github/workflows/rdme-custompages.yml) to GitHub šŸš€ +1. Push your newly created file (.github/workflows/rdme-custompages-with-github-flag.yml) to GitHub šŸš€ 2. Create a GitHub secret called README_API_KEY and populate the value with your ReadMe API key (ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢I_KEY) šŸ”‘ šŸ” Check out GitHub's docs for more info on creating encrypted secrets (https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) @@ -219,7 +219,7 @@ Almost done! Just a couple more steps: " `; -exports[`#createGHA command inputs custompages should run GHA creation workflow and generate valid workflow file 4`] = ` +exports[`#createGHA command inputs custompages (single) should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action šŸ¦‰ @@ -227,10 +227,10 @@ name: ReadMe GitHub Action šŸ¦‰ on: push: branches: - # This workflow will run every time you push code to the following branch: \`some-branch\` + # This workflow will run every time you push code to the following branch: \`another-branch\` # Check out GitHub's docs for more info on configuring this: # https://docs.github.com/actions/using-workflows/events-that-trigger-workflows - - some-branch + - another-branch jobs: rdme-custompages: @@ -246,12 +246,12 @@ jobs: " `; -exports[`#createGHA command inputs custompages should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 1`] = ` +exports[`#createGHA command inputs custompages should run GHA creation workflow and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! āœØ Almost done! Just a couple more steps: -1. Push your newly created file (.github/workflows/rdme-custompages-with-github-flag.yml) to GitHub šŸš€ +1. Push your newly created file (.github/workflows/rdme-custompages.yml) to GitHub šŸš€ 2. Create a GitHub secret called README_API_KEY and populate the value with your ReadMe API key (ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢I_KEY) šŸ”‘ šŸ” Check out GitHub's docs for more info on creating encrypted secrets (https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) @@ -260,7 +260,7 @@ Almost done! Just a couple more steps: " `; -exports[`#createGHA command inputs custompages should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 2`] = ` +exports[`#createGHA command inputs custompages should run GHA creation workflow and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action šŸ¦‰ @@ -268,10 +268,10 @@ name: ReadMe GitHub Action šŸ¦‰ on: push: branches: - # This workflow will run every time you push code to the following branch: \`another-branch\` + # This workflow will run every time you push code to the following branch: \`some-branch\` # Check out GitHub's docs for more info on configuring this: # https://docs.github.com/actions/using-workflows/events-that-trigger-workflows - - another-branch + - some-branch jobs: rdme-custompages: @@ -287,7 +287,7 @@ jobs: " `; -exports[`#createGHA command inputs custompages should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 3`] = ` +exports[`#createGHA command inputs custompages should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! āœØ @@ -301,7 +301,7 @@ Almost done! Just a couple more steps: " `; -exports[`#createGHA command inputs custompages should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 4`] = ` +exports[`#createGHA command inputs custompages should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action šŸ¦‰ @@ -324,11 +324,11 @@ jobs: - name: Run \`custompages\` command šŸš€ uses: readmeio/rdme@v7 with: - rdme: custompages ./custompages/rdme.md --key=\${{ secrets.README_API_KEY }} + rdme: custompages ./custompages --key=\${{ secrets.README_API_KEY }} " `; -exports[`#createGHA command inputs docs should run GHA creation workflow and generate valid workflow file 1`] = ` +exports[`#createGHA command inputs docs (single) should run GHA creation workflow and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! āœØ @@ -342,7 +342,7 @@ Almost done! Just a couple more steps: " `; -exports[`#createGHA command inputs docs should run GHA creation workflow and generate valid workflow file 2`] = ` +exports[`#createGHA command inputs docs (single) should run GHA creation workflow and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action šŸ¦‰ @@ -365,16 +365,16 @@ jobs: - name: Run \`docs\` command šŸš€ uses: readmeio/rdme@v7 with: - rdme: docs --key=\${{ secrets.README_API_KEY }} --version=1.0.0 + rdme: docs ./docs/rdme.md --key=\${{ secrets.README_API_KEY }} --version=1.0.0 " `; -exports[`#createGHA command inputs docs should run GHA creation workflow and generate valid workflow file 3`] = ` +exports[`#createGHA command inputs docs (single) should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! āœØ Almost done! Just a couple more steps: -1. Push your newly created file (.github/workflows/rdme-docs.yml) to GitHub šŸš€ +1. Push your newly created file (.github/workflows/rdme-docs-with-github-flag.yml) to GitHub šŸš€ 2. Create a GitHub secret called README_API_KEY and populate the value with your ReadMe API key (ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢I_KEY) šŸ”‘ šŸ” Check out GitHub's docs for more info on creating encrypted secrets (https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) @@ -383,7 +383,7 @@ Almost done! Just a couple more steps: " `; -exports[`#createGHA command inputs docs should run GHA creation workflow and generate valid workflow file 4`] = ` +exports[`#createGHA command inputs docs (single) should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action šŸ¦‰ @@ -391,10 +391,10 @@ name: ReadMe GitHub Action šŸ¦‰ on: push: branches: - # This workflow will run every time you push code to the following branch: \`some-branch\` + # This workflow will run every time you push code to the following branch: \`another-branch\` # Check out GitHub's docs for more info on configuring this: # https://docs.github.com/actions/using-workflows/events-that-trigger-workflows - - some-branch + - another-branch jobs: rdme-docs: @@ -410,12 +410,12 @@ jobs: " `; -exports[`#createGHA command inputs docs should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 1`] = ` +exports[`#createGHA command inputs docs should run GHA creation workflow and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! āœØ Almost done! Just a couple more steps: -1. Push your newly created file (.github/workflows/rdme-docs-with-github-flag.yml) to GitHub šŸš€ +1. Push your newly created file (.github/workflows/rdme-docs.yml) to GitHub šŸš€ 2. Create a GitHub secret called README_API_KEY and populate the value with your ReadMe API key (ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢ā€¢I_KEY) šŸ”‘ šŸ” Check out GitHub's docs for more info on creating encrypted secrets (https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) @@ -424,7 +424,7 @@ Almost done! Just a couple more steps: " `; -exports[`#createGHA command inputs docs should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 2`] = ` +exports[`#createGHA command inputs docs should run GHA creation workflow and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action šŸ¦‰ @@ -432,10 +432,10 @@ name: ReadMe GitHub Action šŸ¦‰ on: push: branches: - # This workflow will run every time you push code to the following branch: \`another-branch\` + # This workflow will run every time you push code to the following branch: \`some-branch\` # Check out GitHub's docs for more info on configuring this: # https://docs.github.com/actions/using-workflows/events-that-trigger-workflows - - another-branch + - some-branch jobs: rdme-docs: @@ -451,7 +451,7 @@ jobs: " `; -exports[`#createGHA command inputs docs should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 3`] = ` +exports[`#createGHA command inputs docs should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! āœØ @@ -465,7 +465,7 @@ Almost done! Just a couple more steps: " `; -exports[`#createGHA command inputs docs should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 4`] = ` +exports[`#createGHA command inputs docs should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action šŸ¦‰ @@ -488,7 +488,7 @@ jobs: - name: Run \`docs\` command šŸš€ uses: readmeio/rdme@v7 with: - rdme: docs ./docs/rdme.md --key=\${{ secrets.README_API_KEY }} --version=1.0.0 + rdme: docs --key=\${{ secrets.README_API_KEY }} --version=1.0.0 " `; diff --git a/__tests__/lib/createGHA.test.ts b/__tests__/lib/createGHA.test.ts index 2e44ddc83..52f0801f0 100644 --- a/__tests__/lib/createGHA.test.ts +++ b/__tests__/lib/createGHA.test.ts @@ -50,21 +50,34 @@ describe('#createGHA', () => { describe.each<{ cmd: keyof typeof commands; CmdClass: typeof Command; + /** used to differentiate describe blocks */ + label: string; opts: CommandOptions>; }>([ - { cmd: 'openapi:validate', CmdClass: OpenAPIValidateCommand, opts: { spec: 'petstore.json' } }, - { cmd: 'openapi', CmdClass: OpenAPICommand, opts: { key, spec: 'petstore.json', id: 'spec_id' } }, - { cmd: 'docs', CmdClass: DocsCommand, opts: { key, folder: './docs', version: '1.0.0' } }, - { cmd: 'docs', CmdClass: DocsCommand, opts: { key, filePath: './docs/rdme.md', version: '1.0.0' } }, - { cmd: 'changelogs', CmdClass: ChangelogsCommand, opts: { key, filePath: './changelogs' } }, - { cmd: 'changelogs', CmdClass: ChangelogsCommand, opts: { key, filePath: './changelogs/rdme.md' } }, - { cmd: 'custompages', CmdClass: CustomPagesCommand, opts: { key, filePath: './custompages' } }, + { cmd: 'openapi:validate', CmdClass: OpenAPIValidateCommand, opts: { spec: 'petstore.json' }, label: '' }, + { cmd: 'openapi', CmdClass: OpenAPICommand, opts: { key, spec: 'petstore.json', id: 'spec_id' }, label: '' }, + { cmd: 'docs', CmdClass: DocsCommand, opts: { key, folder: './docs', version: '1.0.0' }, label: '' }, + { + cmd: 'docs', + CmdClass: DocsCommand, + label: ' (single)', + opts: { key, filePath: './docs/rdme.md', version: '1.0.0' }, + }, + { cmd: 'changelogs', CmdClass: ChangelogsCommand, opts: { key, filePath: './changelogs' }, label: '' }, + { + cmd: 'changelogs', + CmdClass: ChangelogsCommand, + label: ' (single)', + opts: { key, filePath: './changelogs/rdme.md' }, + }, + { cmd: 'custompages', CmdClass: CustomPagesCommand, opts: { key, filePath: './custompages' }, label: '' }, { cmd: 'custompages', CmdClass: CustomPagesCommand, + label: ' (single)', opts: { key, filePath: './custompages/rdme.md' }, }, - ])('$cmd', ({ cmd, CmdClass, opts }) => { + ])('$cmd$label', ({ cmd, CmdClass, opts }) => { let command; beforeEach(() => { @@ -167,6 +180,12 @@ describe('#createGHA', () => { return expect(createGHA('success!', cmd, command.args, opts)).resolves.toBe('success!'); }); + it('should not run if unable to connect to remote', () => { + git.remote = getGitRemoteMock('bad-remote', 'http://somebadurl.git'); + + return expect(createGHA('success!', cmd, command.args, opts)).resolves.toBe('success!'); + }); + it('should not run if user previously declined to set up GHA for current directory + pkg version', async () => { const repoRoot = process.cwd(); @@ -191,7 +210,7 @@ describe('#createGHA', () => { delete process.env.TEST_RDME_NPM_SCRIPT; }); - it('should not run if repo only contains non-GitHub remotes', () => { + it('should not run if repo solely contains non-GitHub remotes', () => { git.remote = getGitRemoteMock('origin', 'https://gitlab.com', 'main'); return expect(createGHA('success!', cmd, command.args, opts)).resolves.toBe('success!'); diff --git a/src/lib/baseCommand.ts b/src/lib/baseCommand.ts index 03b4a4207..2b361ce71 100644 --- a/src/lib/baseCommand.ts +++ b/src/lib/baseCommand.ts @@ -102,7 +102,7 @@ export default class Command { )} is currently logged in, using the stored API key for this project: ${chalk.blue( configstore.get('project') )}`, - false + { includeEmojiPrefix: false } ); } @@ -110,9 +110,9 @@ export default class Command { if (isCI()) { throw new Error('No project API key provided. Please use `--key`.'); } - info("Looks like you're missing a ReadMe API key, let's fix that! šŸ¦‰", false); + info("Looks like you're missing a ReadMe API key, let's fix that! šŸ¦‰", { includeEmojiPrefix: false }); const result = await loginFlow(); - info(result, false); + info(result, { includeEmojiPrefix: false }); // eslint-disable-next-line no-param-reassign opts.key = configstore.get('apiKey'); } diff --git a/src/lib/createGHA/index.ts b/src/lib/createGHA/index.ts index b8b385196..e9472eaa8 100644 --- a/src/lib/createGHA/index.ts +++ b/src/lib/createGHA/index.ts @@ -111,7 +111,11 @@ export async function getGitData() { if (rawRemotes) { const remote = rawRemotes.split('\n')[0]; debug(`[getGitData] remote result: ${remote}`); - const rawRemote = await git.remote(['show', remote]); + const rawRemote = await git.remote(['show', remote]).catch(e => { + debug(`[getGitData] error accessing remote: ${e.message}`); + return ''; + }); + debug(`[getGitData] rawRemote result: ${rawRemote}`); // Extract head branch from git output const rawHead = headLineRegEx.exec(rawRemote as string)?.[0]; @@ -155,6 +159,7 @@ export default async function createGHA( // if in a CI environment, // don't even bother running the git commands if (!opts.github && (isCI() || isNpmScript())) { + debug('not running GHA onboarding workflow in CI and/or npm script, exiting'); return msg; } @@ -183,10 +188,10 @@ export default async function createGHA( } } - if (msg) info(msg, false); + if (msg) info(msg, { includeEmojiPrefix: false }); if (opts.github) { - info(chalk.bold("\nšŸš€ Let's get you set up with GitHub Actions! šŸš€\n", false)); + info(chalk.bold("\nšŸš€ Let's get you set up with GitHub Actions! šŸš€\n"), { includeEmojiPrefix: false }); } else { info( [ @@ -200,7 +205,7 @@ export default async function createGHA( `āœØ This means it will run ${chalk.italic('automagically')} with every push to a branch of your choice!`, '', ].join('\n'), - false + { includeEmojiPrefix: false } ); } diff --git a/src/lib/logger.ts b/src/lib/logger.ts index f4e3d40e3..b2e2cdc69 100644 --- a/src/lib/logger.ts +++ b/src/lib/logger.ts @@ -31,14 +31,19 @@ function error(input: string) { /** * Wrapper for info/notice statements. - * @param {Boolean} includeEmojiPrefix whether or not to prefix - * the statement with this emoji: ā„¹ļø + */ -function info(input: string, includeEmojiPrefix = true) { +function info( + input: string, + opts = { + /** whether or not to prefix * the statement with this emoji: ā„¹ļø */ + includeEmojiPrefix: true, + } +) { /* istanbul ignore next */ if (isGHA() && !isTest()) return core.notice(input); /* istanbul ignore next */ - if (!includeEmojiPrefix) return console.info(input); // eslint-disable-line no-console + if (!opts.includeEmojiPrefix) return console.info(input); // eslint-disable-line no-console // eslint-disable-next-line no-console return console.info(`ā„¹ļø ${input}`); }