Skip to content

Commit

Permalink
feat: add defaults for repoUrl from package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit-gohri committed Feb 15, 2020
1 parent b3f8ee9 commit 6c5d519
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function getCreatedOrModifiedFiles() {

export type GenerateRepoUrl = (filepath: string) => string

export type RepoUrl = string | GenerateRepoUrl
export type RepoUrl = string | GenerateRepoUrl | boolean

export type IgnorePatterns = (string | RegExp)[]

Expand Down Expand Up @@ -55,6 +55,15 @@ export function getMatches(diffString: string, keyword: string) {

export function getFormattedSrcLink(filepath: string, repoUrl?: RepoUrl) {
let srcLink = `\`${filepath}\``
if (repoUrl === true) {
try {
const packageFile = require(`${process.cwd()}/package.json`)
repoUrl = packageFile.repository.url.replace(/\.git$/, '')
}
catch (err) {
//
}
}
// Github url
if (typeof repoUrl === "string") {
srcLink = `[${filepath}](${repoUrl}/blob/${danger.git.commits[0].sha}/${filepath})`
Expand All @@ -68,7 +77,7 @@ export function getFormattedSrcLink(filepath: string, repoUrl?: RepoUrl) {
* A danger-js plugin to list all todos/fixmes/etc added/changed in a PR
*/
export default async function todos({
repoUrl,
repoUrl = true,
ignore = [],
keywords = ["TODO", "FIXME"],
}: {
Expand Down

0 comments on commit 6c5d519

Please sign in to comment.