From a1aa321298aa948154c1076b4ea8809f209e0298 Mon Sep 17 00:00:00 2001 From: Tal Bereznitskey Date: Fri, 1 May 2020 10:13:04 +0300 Subject: [PATCH 1/4] Bug fix: Code-owner links are breaking the extension --- src/js/lib.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/js/lib.js b/src/js/lib.js index f0df779..e045f70 100644 --- a/src/js/lib.js +++ b/src/js/lib.js @@ -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) => { @@ -129,9 +133,13 @@ export const createFileTree = (filter = EMPTY_FILTER) => { if (!node) { const hrefSplit = href.split('#') const fileId = hrefSplit[hrefSplit.length - 1] + const diffElement = getDiffElement(fileId) + if (!diffElement) { + return + } + const hasComments = (countCommentsForFileId(fileId) > 0) const isDeleted = isDeletedForFileId(fileId) - const diffElement = getDiffElement(fileId) tree.diffElements.push(diffElement) node = { nodeLabel: part, @@ -177,9 +185,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 } From 7bebb0c8549e87979e3ccd2a8964c1df6cbf02f3 Mon Sep 17 00:00:00 2001 From: Tal Bereznitskey Date: Fri, 1 May 2020 10:21:15 +0300 Subject: [PATCH 2/4] Update deplot scripts --- src/js/lib.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/js/lib.js b/src/js/lib.js index e045f70..5bccd6d 100644 --- a/src/js/lib.js +++ b/src/js/lib.js @@ -134,23 +134,21 @@ export const createFileTree = (filter = EMPTY_FILTER) => { const hrefSplit = href.split('#') const fileId = hrefSplit[hrefSplit.length - 1] const diffElement = getDiffElement(fileId) - if (!diffElement) { - return + 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) } - - 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 = location.list.sort(sorter) location = node From 6443828a9ba69091dd16ffa998acf189fd4d8fc6 Mon Sep 17 00:00:00 2001 From: Tal Bereznitskey Date: Fri, 1 May 2020 10:42:44 +0300 Subject: [PATCH 3/4] Fix count --- src/js/lib.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/js/lib.js b/src/js/lib.js index 5bccd6d..cab96aa 100644 --- a/src/js/lib.js +++ b/src/js/lib.js @@ -119,6 +119,7 @@ export const createFileTree = (filter = EMPTY_FILTER) => { title = getCurrentFileLocation(title) return { title, href, parts: title.split('/') } }) + const count = fileInfo.filter(({ href }) => href.includes('#diff')).length const tree = { nodeLabel: '/', list: [], @@ -157,7 +158,7 @@ export const createFileTree = (filter = EMPTY_FILTER) => { }) return { tree: folderConcat(tree), - count: fileInfo.length + count } } From cfaa6c5101e4712eb255f3743cbcd34c44c9d938 Mon Sep 17 00:00:00 2001 From: Tal Bereznitskey Date: Fri, 1 May 2020 10:45:17 +0300 Subject: [PATCH 4/4] Guard check --- src/js/lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/lib.js b/src/js/lib.js index cab96aa..23196b7 100644 --- a/src/js/lib.js +++ b/src/js/lib.js @@ -119,7 +119,7 @@ export const createFileTree = (filter = EMPTY_FILTER) => { title = getCurrentFileLocation(title) return { title, href, parts: title.split('/') } }) - const count = fileInfo.filter(({ href }) => href.includes('#diff')).length + const count = fileInfo.filter(({ href }) => href && href.includes('#diff')).length const tree = { nodeLabel: '/', list: [],