Skip to content

Commit

Permalink
Merge pull request #113 from berzniz/fix_code_owners_links
Browse files Browse the repository at this point in the history
Bug fix: Code-owner links are breaking the extension
  • Loading branch information
berzniz authored May 1, 2020
2 parents 104ef8a + cfaa6c5 commit 4ef3420
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ const getDiffElement = (fileId) => {
return el
}

const gitHubEnterpriseEl = document.querySelector(`[data-anchor="${fileId}"]`).parentElement
return gitHubEnterpriseEl
const gitHubEnterpriseEl = document.querySelector(`[data-anchor="${fileId}"]`)
if (gitHubEnterpriseEl) {
return gitHubEnterpriseEl.parentElement
}

return null
}

const countCommentsForFileId = (fileId) => {
Expand Down Expand Up @@ -115,6 +119,7 @@ export const createFileTree = (filter = EMPTY_FILTER) => {
title = getCurrentFileLocation(title)
return { title, href, parts: title.split('/') }
})
const count = fileInfo.filter(({ href }) => href && href.includes('#diff')).length
const tree = {
nodeLabel: '/',
list: [],
Expand All @@ -129,20 +134,22 @@ export const createFileTree = (filter = EMPTY_FILTER) => {
if (!node) {
const hrefSplit = href.split('#')
const fileId = hrefSplit[hrefSplit.length - 1]
const hasComments = (countCommentsForFileId(fileId) > 0)
const isDeleted = isDeletedForFileId(fileId)
const diffElement = getDiffElement(fileId)
tree.diffElements.push(diffElement)
node = {
nodeLabel: part,
list: [],
href: (index === parts.length - 1) ? href : null,
hasComments,
isDeleted,
diffElement,
diffStats: getDiffStatsForDiffElement(diffElement)
if (diffElement) {
const hasComments = (countCommentsForFileId(fileId) > 0)
const isDeleted = isDeletedForFileId(fileId)
tree.diffElements.push(diffElement)
node = {
nodeLabel: part,
list: [],
href: (index === parts.length - 1) ? href : null,
hasComments,
isDeleted,
diffElement,
diffStats: getDiffStatsForDiffElement(diffElement)
}
location.list.push(node)
}
location.list.push(node)
}
location.list = location.list.sort(sorter)
location = node
Expand All @@ -151,7 +158,7 @@ export const createFileTree = (filter = EMPTY_FILTER) => {
})
return {
tree: folderConcat(tree),
count: fileInfo.length
count
}
}

Expand All @@ -177,9 +184,9 @@ const EMPTY_FILTER = ''

export const getBrowserApi = () => {
let browserApi = window.chrome
if (typeof browser !== 'undefined') {
browserApi = browser
}
if (typeof browser !== 'undefined') {
browserApi = browser
}
return browserApi
}

Expand Down

0 comments on commit 4ef3420

Please sign in to comment.