Skip to content

Commit 15e2fc4

Browse files
committed
Refactor: use find-githost
1 parent 3876b0f commit 15e2fc4

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

index.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const deglob = require('deglob')
44
const find = require('find-file-up')
5+
const Githost = require('find-githost')
56
const engine = require('unified-engine')
67
const color = require('supports-color').stdout
78
const fromCallback = require('catering').fromCallback
@@ -17,7 +18,7 @@ function hallmark (options, callback) {
1718
const pkg = read('package.json', cwd) || {}
1819
const rc = Object.assign({}, read('.hallmarkrc', cwd), pkg.hallmark)
1920
const files = first('files', options, rc) || ['*.md']
20-
const repository = repo(first('repository', options, rc, pkg)) || originRepo(cwd) || ''
21+
const repository = repo(cwd, options, rc, pkg)
2122
const ignore = concat('ignore', rc, options)
2223

2324
deglob(files, { usePackageJson: false, cwd, ignore }, function (err, files) {
@@ -178,8 +179,20 @@ function first (key, ...sources) {
178179
}
179180
}
180181

181-
function repo (repository) {
182-
return repository ? repository.url || repository : null
182+
function repo (cwd, options, rc, pkg) {
183+
const override = options.repository || rc.repository
184+
const committish = false
185+
186+
if (override) {
187+
return Githost.fromUrl(override, { committish }).https()
188+
}
189+
190+
const host = (
191+
Githost.fromPkg(pkg, { committish, optional: true }) ||
192+
Githost.fromGit(cwd, { committish })
193+
)
194+
195+
return host.https()
183196
}
184197

185198
function concat (key, rc, options) {
@@ -192,11 +205,3 @@ function collapseToc () {
192205
summary: 'Click to expand'
193206
}
194207
}
195-
196-
function originRepo (cwd) {
197-
// Don't pass cwd for now (jonschlinkert/parse-git-config#13)
198-
const origin = require('remote-origin-url').sync(/* cwd */)
199-
const ghurl = require('github-url-from-git')
200-
201-
return origin ? ghurl(origin) : null
202-
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"catering": "^2.0.0",
2323
"deglob": "^4.0.0",
2424
"find-file-up": "^2.0.1",
25-
"github-url-from-git": "^1.5.0",
25+
"find-githost": "^1.0.0",
2626
"remark": "^12.0.1",
2727
"remark-autolink-references": "^1.0.0",
2828
"remark-collapse": "~0.1.2",
@@ -50,7 +50,6 @@
5050
"remark-lint-table-pipes": "^2.0.1",
5151
"remark-toc": "^7.0.0",
5252
"remark-validate-links": "^10.0.2",
53-
"remote-origin-url": "^2.0.0",
5453
"subarg": "^1.0.0",
5554
"supports-color": "^7.1.0",
5655
"unified-engine": "^8.0.0",

0 commit comments

Comments
 (0)