Skip to content

Commit

Permalink
fix: support https git urls (#2)
Browse files Browse the repository at this point in the history
* fix: support https git urls

* build: remove log
  • Loading branch information
Kikobeats authored Jan 4, 2024
1 parent 9e711b6 commit 4b81c1b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 18 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 0 additions & 2 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
14 changes: 11 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
23 changes: 23 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -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'
}
)
})

0 comments on commit 4b81c1b

Please sign in to comment.