Skip to content

Commit

Permalink
fix(docz-core): try catch on get repo info
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Aug 16, 2018
1 parent 4b2f2fe commit 2016736
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions packages/docz-core/src/utils/repo-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@ export const getRepoUrl = () => {
}

export const getRepoEditUrl = (src: string): string | null => {
const project = path.parse(findup.sync('.git')).dir
const root = path.join(paths.root, src)
const relative = path.relative(project, root)
const tree = path.join('/edit/master', relative)
const repo = parseRepo()
try {
const project = path.parse(findup.sync('.git')).dir
const root = path.join(paths.root, src)
const relative = path.relative(project, root)
const tree = path.join('/edit/master', relative)
const repo = parseRepo()

return (
repo &&
repo.browsetemplate
.replace('{domain}', repo.domain)
.replace('{user}', repo.user)
.replace('{project}', repo.project)
.replace('{/tree/committish}', tree)
)
return (
repo &&
repo.browsetemplate
.replace('{domain}', repo.domain)
.replace('{user}', repo.user)
.replace('{project}', repo.project)
.replace('{/tree/committish}', tree)
)
} catch (err) {
return null
}
}

0 comments on commit 2016736

Please sign in to comment.