Skip to content

Commit

Permalink
fix(createGHA): git remote connection errors (#705)
Browse files Browse the repository at this point in the history
* chore: add smol debug statement

* fix: broken console log yeeeesh

* chore: rename test to not use the word 'only'

* test: rename certain describe blocks, update snapshots

describe blocks weren't being distinguished properly so this fixes that

* fix: catch remote connection errors

* refactor(logger): use opts instead of flag

feedback: #705 (comment)
  • Loading branch information
kanadgupta authored Dec 7, 2022
1 parent 7eb5b29 commit 18f5468
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 68 deletions.
5 changes: 5 additions & 0 deletions __tests__/helpers/get-git-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
}
if (!defaultBranch) return Promise.reject(new Error('Bad mock uh oh')) as unknown as Response<string>;
return Promise.resolve(`* remote origin
Fetch URL: ${remoteUrl}
Expand Down
96 changes: 48 additions & 48 deletions __tests__/lib/__snapshots__/createGHA.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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! ✨
Expand All @@ -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 🦉
Expand All @@ -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)
Expand All @@ -55,18 +55,18 @@ 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 🦉
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:
Expand All @@ -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)
Expand All @@ -96,18 +96,18 @@ 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 🦉
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:
Expand All @@ -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! ✨
Expand All @@ -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 🦉
Expand All @@ -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! ✨
Expand All @@ -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 🦉
Expand All @@ -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)
Expand All @@ -219,18 +219,18 @@ 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 🦉
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:
Expand All @@ -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)
Expand All @@ -260,18 +260,18 @@ 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 🦉
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:
Expand All @@ -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! ✨
Expand All @@ -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 🦉
Expand All @@ -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! ✨
Expand All @@ -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 🦉
Expand All @@ -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)
Expand All @@ -383,18 +383,18 @@ 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 🦉
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:
Expand All @@ -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)
Expand All @@ -424,18 +424,18 @@ 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 🦉
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:
Expand All @@ -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! ✨
Expand All @@ -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 🦉
Expand All @@ -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
"
`;

Expand Down
Loading

0 comments on commit 18f5468

Please sign in to comment.