Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch internal files using the GitHub tree API #690

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fetch internal files using the GitHub tree API
The changes made in #650 caused an issue, which stopped linking relative files in private repos. All files were resolved through the OctoLinker API which obviously doesn't work for private repos.
  • Loading branch information
Stefan Buck committed Oct 21, 2019
commit 544045016d0cefe5977e95bffefa82fa894d1a3d
5 changes: 4 additions & 1 deletion packages/core/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ async function run(rootElement) {
}
}

const [, user, repo] = window.location.pathname.split('/');
const currentRepoSlug = `${user}/${repo}`;

matches = matches
.filter(result => result !== undefined)
.map(({ link, urls }) => {
const urlsSorted = helperSortUrls(urls, link.innerText);

return {
link,
urls: normaliseResolverResults(urlsSorted),
urls: normaliseResolverResults(urlsSorted, currentRepoSlug),
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ Array [
exports[`normaliseResolverResults converts {BASE_URL}/file.js 1`] = `
Array [
Object {
"branch": undefined,
"path": undefined,
"repo": undefined,
"type": "internal-link",
"url": "https://github.com/file.js",
"user": "file.js",
"target": "https://github.com/file.js",
"type": "ping",
},
]
`;
Expand Down Expand Up @@ -65,25 +61,29 @@ Array [
exports[`normaliseResolverResults converts {BASE_URL}/foo/bar/blob/master/file.js,{BASE_URL}/foo/bar/blob/master/file.js 1`] = `
Array [
Object {
"target": "https://github.com/foo/bar/blob/master/file.js",
"type": "ping",
"branch": "master",
"path": "file.js",
"repo": "bar",
"type": "internal-link",
"url": "https://github.com/foo/bar/blob/master/file.js",
"user": "foo",
},
Object {
"target": "https://github.com/foo/bar/blob/master/file.js",
"type": "ping",
"branch": "master",
"path": "file.js",
"repo": "bar",
"type": "internal-link",
"url": "https://github.com/foo/bar/blob/master/file.js",
"user": "foo",
},
]
`;

exports[`normaliseResolverResults converts {BASE_URL}file.js 1`] = `
Array [
Object {
"branch": undefined,
"path": undefined,
"repo": undefined,
"type": "internal-link",
"url": "https://github.comfile.js",
"user": undefined,
"target": "https://github.comfile.js",
"type": "ping",
},
]
`;
Expand Down
4 changes: 2 additions & 2 deletions packages/helper-normalise-resolver-results/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ const registry = ({ registry: type, target }) => ({
target,
});

export default function(urls) {
export default function(urls, slug) {
return [].concat(urls).map(url => {
if (typeof url === 'string') {
if (url.startsWith('{BASE_URL}') && urls.length === 1) {
if (url.startsWith(`{BASE_URL}/${slug}/`)) {
return internal(url);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/helper-normalise-resolver-results/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe('normaliseResolverResults', () => {
{ registry: 'npm', target: 'foo' },
() => {},
])('converts %s', url => {
expect(normaliseResolverResults([].concat(url))).toMatchSnapshot();
expect(
normaliseResolverResults([].concat(url), 'foo/bar'),
).toMatchSnapshot();
});
});