From 4b81c1bf792649674711d2269b223fcee5aab77d Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Thu, 4 Jan 2024 14:06:45 +0100 Subject: [PATCH] fix: support https git urls (#2) * fix: support https git urls * build: remove log --- .github/workflows/main.yml | 12 ++++++------ .github/workflows/pull_request.yml | 12 ++++++------ bin/index.js | 2 -- package.json | 4 +++- src/index.js | 14 +++++++++++--- test/index.js | 23 +++++++++++++++++++++++ 6 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 test/index.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 72ad516..dd60f1a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,12 +52,12 @@ jobs: run_install: true - name: Test run: pnpm test - # - name: Report - # run: npx c8 report --reporter=text-lcov > coverage/lcov.info - # - name: Coverage - # uses: coverallsapp/github-action@main - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Report + run: npx c8 report --reporter=text-lcov > coverage/lcov.info + - name: Coverage + uses: coverallsapp/github-action@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} - name: Release env: GH_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 1802e3c..d4ace7c 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -28,9 +28,9 @@ jobs: run_install: true - name: Test run: pnpm test - # - name: Report - # run: npx c8 report --reporter=text-lcov > coverage/lcov.info - # - name: Coverage - # uses: coverallsapp/github-action@main - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Report + run: npx c8 report --reporter=text-lcov > coverage/lcov.info + - name: Coverage + uses: coverallsapp/github-action@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/bin/index.js b/bin/index.js index 295a219..b9c3e56 100755 --- a/bin/index.js +++ b/bin/index.js @@ -14,8 +14,6 @@ const { _, ...flags } = mri(process.argv.slice(2), { } }) -console.log('DEBUG url', flags.url) - if (flags.help) { console.log(require('fs').readFileSync('./help.txt', 'utf8')) process.exit(0) diff --git a/package.json b/package.json index 2759912..70b04ed 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,8 @@ "@commitlint/cli": "latest", "@commitlint/config-conventional": "latest", "@ksmithut/prettier-standard": "latest", + "ava": "latest", + "c8": "latest", "ci-publish": "latest", "finepack": "latest", "git-authors-cli": "latest", @@ -58,7 +60,7 @@ "release": "standard-version -a", "release:github": "./bin/index.js", "release:tags": "git push --follow-tags origin HEAD:master", - "test": "exit 0" + "test": "c8 ava" }, "preferGlobal": true, "license": "MIT", diff --git a/src/index.js b/src/index.js index c1516b5..afa573e 100644 --- a/src/index.js +++ b/src/index.js @@ -2,9 +2,17 @@ const gitDetails = opts => { if (opts.owner && opts.repo) return opts - const regex = /github\.com[:/](.*?)\/(.*?)\.git/ - const [, owner, repo] = opts.url.match(regex) - return { owner, repo } + + const regex = + /(?:git@github\.com:|https:\/\/github\.com\/)(.*?)\/(.*?)(?:\.git)?$/ + const match = opts.url.match(regex) + + if (match) { + const [, owner, repo] = match + return { owner, repo } + } + + throw new TypeError(`Invalid git url: ${opts.url}`) } const createGithubAPI = diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..79e192e --- /dev/null +++ b/test/index.js @@ -0,0 +1,23 @@ +'use strict' + +const test = require('ava') + +const { gitDetails } = require('..') + +test('.gitDetails', t => { + t.deepEqual( + gitDetails({ url: 'git@github.com:kikobeats/github-generate-release.git' }), + { + owner: 'kikobeats', + repo: 'github-generate-release' + } + ) + + t.deepEqual( + gitDetails({ url: 'https://github.com/kikobeats/github-generate-release' }), + { + owner: 'kikobeats', + repo: 'github-generate-release' + } + ) +})