Skip to content

Commit

Permalink
Fix blob reader (OctoLinker#1427)
Browse files Browse the repository at this point in the history
* Ensure unit tests use latest fixtures

* Update fixture files

* Adjust blob reader to dom changes made by github
  • Loading branch information
stefanbuck authored Dec 30, 2021
1 parent 772e11b commit 80ed30d
Show file tree
Hide file tree
Showing 9 changed files with 7,492 additions and 4,181 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
node-version: 16
cache: 'yarn'
- run: yarn install
- run: ./packages/blob-reader/scripts/update-fixtures.sh
- run: yarn test
- run: yarn build
- name: Run E2E
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1,050 changes: 539 additions & 511 deletions packages/blob-reader/fixtures/github.com/issue/code.html

Large diffs are not rendered by default.

3,183 changes: 1,843 additions & 1,340 deletions packages/blob-reader/fixtures/github.com/pull/comments.html

Large diffs are not rendered by default.

2,163 changes: 1,539 additions & 624 deletions packages/blob-reader/fixtures/github.com/pull/diff.html

Large diffs are not rendered by default.

27 changes: 6 additions & 21 deletions packages/blob-reader/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,19 @@ function getPath(el) {
}

// When current page is a gist, get path from blob name
if (!ret && isGist()) {
if (isGist()) {
ret = $('.gist-blob-name', el.parentElement).text().trim();
if (ret && !ret.startsWith('/')) {
ret = `/${ret}`;
}
}

// when page has pull request comment(s)
const $fileHeader = $('.file-header', el.parentElement);
const $fileHeader = $('summary', el.parentElement.parentElement);
if (!ret && $fileHeader.length) {
let repoPath = '';
let filePath = '';

if ($('a.file-action', $fileHeader).length) {
// comment is outdated

filePath = $('.file-info', $fileHeader).text();
repoPath = $('a.file-action', $fileHeader).attr('href');
} else {
// comment is up-to-date

filePath = $('a', $fileHeader).text();
repoPath = $('a', $fileHeader).attr('href');
}

if (repoPath && filePath) {
ret = mergeRepoAndFilePath(repoPath, filePath);
}
const filePath = $('a', $fileHeader).text();
const repoPath = $('a', $fileHeader).attr('href');
ret = mergeRepoAndFilePath(repoPath, filePath);
}

return ret ? ret.trim() : undefined;
Expand Down Expand Up @@ -137,7 +122,7 @@ function diffMetaInformation(el) {
const td = $(el).closest('td').get(0);

// Blob view
if (td.classList.contains('js-file-line')) {
if (td.id.startsWith('LC') || isGist()) {
return {};
}

Expand Down

0 comments on commit 80ed30d

Please sign in to comment.