Skip to content

Commit

Permalink
Adjust resolvers to return a single string or an array of strings whe…
Browse files Browse the repository at this point in the history
…never possible (OctoLinker#476)
  • Loading branch information
stefanbuck authored and josephfrazier committed Jun 18, 2018
1 parent 223984b commit 5d4edbd
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 55 deletions.
10 changes: 7 additions & 3 deletions packages/core/click-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,29 @@ function getResolverUrls(urls) {
return null;
}

// github-search resolver returns a function
if (typeof url === 'function') {
return {
func: url,
};
}

if (typeof url === 'object') {
// Live-query resolver results
if (url.startsWith('https://githublinker.herokuapp.com')) {
return {
url: url.url.replace('{BASE_URL}', BASE_URL),
method: url.method,
url,
method: 'GET',
};
}

// Relative file
if (url.startsWith('{BASE_URL}') || url.startsWith(BASE_URL)) {
return {
url: url.replace('{BASE_URL}', BASE_URL),
};
}

// External urls
return {
url: `https://githublinker.herokuapp.com/ping?url=${url}`,
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
name: 'CSS',

resolve(path, [target]) {
return [relativeFile({ path, target })];
return relativeFile({ path, target });
},

getPattern() {
Expand Down
21 changes: 10 additions & 11 deletions packages/plugin-docker/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
import assert from 'assert';
import dockerImage from '../index';

describe('docker-image', () => {
const path = '/blob/path/dummy';

it('resolves foo to https://hub.docker.com/_/foo', () => {
assert.deepEqual(dockerImage.resolve(path, ['foo']), [
expect(dockerImage.resolve(path, ['foo'])).toBe(
'https://hub.docker.com/_/foo',
]);
);
});

it('resolves foo:1.2.3 to https://hub.docker.com/_/foo', () => {
assert.deepEqual(dockerImage.resolve(path, ['foo:1.2.3']), [
expect(dockerImage.resolve(path, ['foo:1.2.3'])).toBe(
'https://hub.docker.com/_/foo',
]);
);
});

it('resolves foo:1.2.3-alpha to https://hub.docker.com/_/foo', () => {
assert.deepEqual(dockerImage.resolve(path, ['foo:1.2.3-alpha']), [
expect(dockerImage.resolve(path, ['foo:1.2.3-alpha'])).toBe(
'https://hub.docker.com/_/foo',
]);
);
});

it('resolves foo/bar to https://hub.docker.com/r/foo/bar', () => {
assert.deepEqual(dockerImage.resolve(path, ['foo/bar']), [
expect(dockerImage.resolve(path, ['foo/bar'])).toBe(
'https://hub.docker.com/r/foo/bar',
]);
);
});

it('resolves foo/bar:1.2.3 to https://hub.docker.com/r/foo/bar', () => {
assert.deepEqual(dockerImage.resolve(path, ['foo/bar:1.2.3']), [
expect(dockerImage.resolve(path, ['foo/bar:1.2.3'])).toBe(
'https://hub.docker.com/r/foo/bar',
]);
);
});
});
2 changes: 1 addition & 1 deletion packages/plugin-docker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
isOffical = false;
}

return [`https://hub.docker.com/${isOffical ? '_' : 'r'}/${imageName}`];
return `https://hub.docker.com/${isOffical ? '_' : 'r'}/${imageName}`;
},

getPattern() {
Expand Down
12 changes: 5 additions & 7 deletions packages/plugin-dot-net-core/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import assert from 'assert';
import dotNetCore from '../index';

describe('dotNetCore', () => {
const path = '/blob/path/dummy';

it('resolves Microsoft.NETCore.App to https://www.nuget.org/packages/Microsoft.NETCore.App', () => {
assert.deepEqual(dotNetCore.resolve(path, ['Microsoft.NETCore.App']), [
expect(dotNetCore.resolve(path, ['Microsoft.NETCore.App'])).toBe(
'https://www.nuget.org/packages/Microsoft.NETCore.App',
]);
);
});

it('resolves Microsoft.Extensions.Configuration.FileExtensions to https://www.nuget.org/packages/Microsoft.Extensions.Configuration.FileExtensions', () => {
assert.deepEqual(
expect(
dotNetCore.resolve(path, [
'Microsoft.Extensions.Configuration.FileExtensions',
]),
[
'https://www.nuget.org/packages/Microsoft.Extensions.Configuration.FileExtensions',
],
).toBe(
'https://www.nuget.org/packages/Microsoft.Extensions.Configuration.FileExtensions',
);
});
});
9 changes: 4 additions & 5 deletions packages/plugin-dot-net/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import assert from 'assert';
import dotNet from '../index';

describe('dotNet', () => {
const path = '/blob/path/dummy';

it('resolves EntityFramework to https://www.nuget.org/packages/EntityFramework', () => {
assert.deepEqual(dotNet.resolve(path, ['EntityFramework']), [
expect(dotNet.resolve(path, ['EntityFramework'])).toBe(
'https://www.nuget.org/packages/EntityFramework',
]);
);
});

it('resolves Stanford.NLP.CoreNLP to https://www.nuget.org/packages/Stanford.NLP.CoreNLP', () => {
assert.deepEqual(dotNet.resolve(path, ['Stanford.NLP.CoreNLP']), [
expect(dotNet.resolve(path, ['Stanford.NLP.CoreNLP'])).toBe(
'https://www.nuget.org/packages/Stanford.NLP.CoreNLP',
]);
);
});
});
2 changes: 1 addition & 1 deletion packages/plugin-html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
name: 'HTML',

resolve(path, [target]) {
return [relativeFile({ path, target })];
return relativeFile({ path, target });
},

getPattern() {
Expand Down
7 changes: 3 additions & 4 deletions packages/plugin-java/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ describe('Java', () => {
});

it('resolves community packages', () => {
assert.deepEqual(Java.resolve(path, ['com.company.app']), {
url: 'https://githublinker.herokuapp.com/q/java/com.company.app',
method: 'GET',
});
expect(Java.resolve(path, ['com.company.app'])).toBe(
'https://githublinker.herokuapp.com/q/java/com.company.app',
);
});
});
7 changes: 2 additions & 5 deletions packages/plugin-javascript/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ describe('javascript-universal', () => {

it("resolves '@angular/core/bar.js' to '@angular/core'", () => {
const type = 'npm';
expect(plugin.resolve(path, ['@angular/core/bar.js'], { type })[0]).toEqual(
{
url: 'https://githublinker.herokuapp.com/q/npm/@angular/core',
method: 'GET',
},
expect(plugin.resolve(path, ['@angular/core/bar.js'], { type })[0]).toBe(
'https://githublinker.herokuapp.com/q/npm/@angular/core',
);
});

Expand Down
10 changes: 4 additions & 6 deletions packages/plugin-requirements-txt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ export default {
name: 'RequirementsTxt',

resolve(path, [target]) {
return [
liveResolverQuery({
target,
type: 'pypi',
}),
];
return liveResolverQuery({
target,
type: 'pypi',
});
},

getPattern() {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ruby/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
return `{BASE_URL}${join(basePath, `${target}.rb`)}`;
}

return [liveResolverQuery({ type: 'rubygems', target })];
return liveResolverQuery({ type: 'rubygems', target });
},

getPattern() {
Expand Down
8 changes: 3 additions & 5 deletions packages/plugin-rust/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import assert from 'assert';
import rustCrate from '../index';

describe('rust-crate', () => {
const path = '/blob/path/dummy';

it('resolves hamcrest using the live-resolver', () => {
assert.deepEqual(rustCrate.resolve(path, ['hamcrest']), {
url: 'https://githublinker.herokuapp.com/q/crates/hamcrest',
method: 'GET',
});
expect(rustCrate.resolve(path, ['hamcrest'])).toBe(
'https://githublinker.herokuapp.com/q/crates/hamcrest',
);
});
});
5 changes: 1 addition & 4 deletions packages/resolver-live-query/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export default function({ type, target }) {
return {
url: `https://githublinker.herokuapp.com/q/${type}/${target}`,
method: 'GET',
};
return `https://githublinker.herokuapp.com/q/${type}/${target}`;
}
2 changes: 1 addition & 1 deletion packages/resolver-nuget/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function({ target }) {
return [`https://www.nuget.org/packages/${target}`];
return `https://www.nuget.org/packages/${target}`;
}

0 comments on commit 5d4edbd

Please sign in to comment.