Skip to content

Commit

Permalink
feat: add support for blame/history links for gitlab and bitbucket
Browse files Browse the repository at this point in the history
  • Loading branch information
keevan committed Mar 7, 2022
1 parent ec0365d commit 790bf93
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/git-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export default {
return commitHash
},

/**
* Returns a path relative to the git repository root for the file. Note
* though the path is relative from the git repo root, it begins with a
* forward slash
*/
async getRelativePath(path) {
let filePath = forwardFilePath(path);
const { stdout: rootDirectory } = await git(['rev-parse', '--show-toplevel'])
Expand Down
26 changes: 23 additions & 3 deletions lib/platforms/bitbucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,28 @@ export default function ({ repo }) {
// Otherwise..
return false
},
getSelectionLink: ({ commitHash, relativePath, start, end }) => `${repo}/src/${toShortHash(commitHash)}${relativePath}#lines-${start}:${end}`,
getLineLink: ({ commitHash, relativePath, start }) => `${repo}/src/${toShortHash(commitHash)}${relativePath}#lines-${start}`,
getFileLink: ({ commitHash, relativePath }) => `${repo}/src/${toShortHash(commitHash)}${relativePath}`,
getSelectionLink: ({ commitHash, relativePath, start, end, blame = false }) => {
let mode = 'src'
if (blame) {
mode = 'annotate'
}
return `${repo}/${mode}/${toShortHash(commitHash)}${relativePath}#-${start}:${end}`
},
getLineLink: ({ commitHash, relativePath, start, blame = false }) => {
let mode = 'src'
if (blame) {
mode = 'annotate'
}
return `${repo}/${mode}/${toShortHash(commitHash)}${relativePath}#-${start}`
},
getFileLink: ({ commitHash, relativePath, blame = false, history = false }) => {
let mode = 'src'
if (blame) {
mode = 'annotate'
} else if (history) {
mode = 'commits'
}
return `${repo}/${mode}/${toShortHash(commitHash)}${relativePath}`
},
}
}
26 changes: 23 additions & 3 deletions lib/platforms/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,28 @@ export default function ({ repo }) {
// Otherwise..
return false
},
getSelectionLink: ({ commitHash, relativePath, start, end }) => `${repo}/-/blob/${toShortHash(commitHash)}${relativePath}#L${start}-${end}`,
getLineLink: ({ commitHash, relativePath, start }) => `${repo}/-/blob/${toShortHash(commitHash)}${relativePath}#L${start}`,
getFileLink: ({ commitHash, relativePath }) => `${repo}/-/blob/${toShortHash(commitHash)}${relativePath}`,
getSelectionLink: ({ commitHash, relativePath, start, end, blame = false }) => {
let mode = 'blob'
if (blame) {
mode = 'blame'
}
return `${repo}/-/${mode}/${toShortHash(commitHash)}${relativePath}#L${start}-${end}`
},
getLineLink: ({ commitHash, relativePath, start, blame = false }) => {
let mode = 'blob'
if (blame) {
mode = 'blame'
}
return `${repo}/-/${mode}/${toShortHash(commitHash)}${relativePath}#L${start}`
},
getFileLink: ({ commitHash, relativePath, blame = false, history = false }) => {
let mode = 'blob'
if (blame) {
mode = 'blame'
} else if (history) {
mode = 'commits'
}
return `${repo}/-/${mode}/${toShortHash(commitHash)}${relativePath}`
},
}
}

0 comments on commit 790bf93

Please sign in to comment.