Skip to content

Commit

Permalink
feat(repology): Support all repositories of repology (#7833)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
danez and viceice committed Dec 1, 2020
1 parent c63ffa5 commit e3ccc35
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 225 deletions.
94 changes: 7 additions & 87 deletions lib/datasource/repology/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Array [
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=debian_stable&name_type=binname&target_page=api_v1_project&noautoresolve=on&name=nginx",
"url": "https://repology.org/api/v1/project/nginx",
},
]
`;
Expand All @@ -45,7 +45,7 @@ Array [
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=debian_stable&name_type=binname&target_page=api_v1_project&noautoresolve=on&name=pulseaudio-utils",
"url": "https://repology.org/api/v1/project/pulseaudio-utils",
},
]
`;
Expand All @@ -70,7 +70,7 @@ Array [
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=alpine_3_12&name_type=binname&target_page=api_v1_project&noautoresolve=on&name=gcc",
"url": "https://repology.org/api/v1/project/gcc",
},
]
`;
Expand All @@ -95,17 +95,7 @@ Array [
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=debian_stable&name_type=binname&target_page=api_v1_project&noautoresolve=on&name=gcc-defaults",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "repology.org",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=debian_stable&name_type=srcname&target_page=api_v1_project&noautoresolve=on&name=gcc-defaults",
"url": "https://repology.org/api/v1/project/gcc-defaults",
},
]
`;
Expand All @@ -120,17 +110,7 @@ Array [
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=debian_stable&name_type=binname&target_page=api_v1_project&noautoresolve=on&name=nginx",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "repology.org",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=debian_stable&name_type=srcname&target_page=api_v1_project&noautoresolve=on&name=nginx",
"url": "https://repology.org/api/v1/project/nginx",
},
]
`;
Expand All @@ -145,42 +125,7 @@ Array [
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=this_should&name_type=binname&target_page=api_v1_project&noautoresolve=on&name=never-exist",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "repology.org",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=this_should&name_type=srcname&target_page=api_v1_project&noautoresolve=on&name=never-exist",
},
]
`;

exports[`datasource/repology/index getReleases returns null for unsupported repository 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "repology.org",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=unsupported_repo&name_type=binname&target_page=api_v1_project&noautoresolve=on&name=nginx",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "repology.org",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=unsupported_repo&name_type=srcname&target_page=api_v1_project&noautoresolve=on&name=nginx",
"url": "https://repology.org/api/v1/project/never-exist",
},
]
`;
Expand All @@ -195,32 +140,7 @@ Array [
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=debian_stable&name_type=binname&target_page=api_v1_project&noautoresolve=on&name=nginx",
},
]
`;

exports[`datasource/repology/index getReleases throws error on unexpected response during source package lookup 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "repology.org",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=debian_stable&name_type=binname&target_page=api_v1_project&noautoresolve=on&name=nginx",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"host": "repology.org",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://repology.org/tools/project-by?repo=debian_stable&name_type=srcname&target_page=api_v1_project&noautoresolve=on&name=nginx",
"url": "https://repology.org/api/v1/project/nginx",
},
]
`;
Expand Down
119 changes: 17 additions & 102 deletions lib/datasource/repology/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,15 @@ import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages';
import { id as versioning } from '../../versioning/loose';
import { RepologyPackage, id as datasource } from '.';

const repologyApiHost = 'https://repology.org/';
const repologyApiHost = 'https://repology.org/api/v1/';

type ResponseMock = { status: number; body?: string };

const mockProjectBy = (
repo: string,
name: string,
binary: ResponseMock,
source: ResponseMock
) => {
const endpoint = '/tools/project-by';
const defaultParams = {
target_page: 'api_v1_project',
noautoresolve: 'on',
};

if (binary) {
httpMock
.scope(repologyApiHost)
.get(endpoint)
.query({ ...defaultParams, repo, name, name_type: 'binname' })
.reply(binary.status, binary.body);
}

if (source) {
httpMock
.scope(repologyApiHost)
.get(endpoint)
.query({ ...defaultParams, repo, name, name_type: 'srcname' })
.reply(source.status, source.body);
}
const mockProjectBy = (name: string, response: ResponseMock) => {
httpMock
.scope(repologyApiHost)
.get(`/project/${name}`)
.reply(response.status, response.body);
};

const fixtureNginx = fs.readFileSync(
Expand Down Expand Up @@ -65,12 +43,7 @@ describe(getName(__filename), () => {
afterEach(() => httpMock.reset());

it('returns null for empty result', async () => {
mockProjectBy(
'debian_stable',
'nginx',
{ status: 200, body: '[]' },
{ status: 200, body: '[]' }
);
mockProjectBy('nginx', { status: 200, body: '[]' });

expect(
await getPkgReleases({
Expand All @@ -83,12 +56,7 @@ describe(getName(__filename), () => {
});

it('returns null for missing repository or package', async () => {
mockProjectBy(
'this_should',
'never-exist',
{ status: 404 },
{ status: 404 }
);
mockProjectBy('never-exist', { status: 404 });

expect(
await getPkgReleases({
Expand All @@ -100,39 +68,8 @@ describe(getName(__filename), () => {
expect(httpMock.getTrace()).toMatchSnapshot();
});

it('returns null for unsupported repository', async () => {
mockProjectBy(
'unsupported_repo',
'nginx',
{ status: 403 },
{ status: 403 }
);

expect(
await getPkgReleases({
datasource,
versioning,
depName: 'unsupported_repo/nginx',
})
).toBeNull();
expect(httpMock.getTrace()).toMatchSnapshot();
});

it('throws error on unexpected response during binary package lookup', async () => {
mockProjectBy('debian_stable', 'nginx', { status: 500 }, null);

await expect(
getPkgReleases({
datasource,
versioning,
depName: 'debian_stable/nginx',
})
).rejects.toThrow(EXTERNAL_HOST_ERROR);
expect(httpMock.getTrace()).toMatchSnapshot();
});

it('throws error on unexpected response during source package lookup', async () => {
mockProjectBy('debian_stable', 'nginx', { status: 404 }, { status: 500 });
mockProjectBy('nginx', { status: 500 });

await expect(
getPkgReleases({
Expand All @@ -156,12 +93,7 @@ describe(getName(__filename), () => {
});

it('returns correct version for binary package', async () => {
mockProjectBy(
'debian_stable',
'nginx',
{ status: 200, body: fixtureNginx },
null
);
mockProjectBy('nginx', { status: 200, body: fixtureNginx });

const res = await getPkgReleases({
datasource,
Expand All @@ -175,12 +107,7 @@ describe(getName(__filename), () => {
});

it('returns correct version for source package', async () => {
mockProjectBy(
'debian_stable',
'gcc-defaults',
{ status: 404 },
{ status: 200, body: fixtureGccDefaults }
);
mockProjectBy('gcc-defaults', { status: 200, body: fixtureGccDefaults });

const res = await getPkgReleases({
datasource,
Expand All @@ -194,12 +121,7 @@ describe(getName(__filename), () => {
});

it('returns correct version for multi-package project with same name', async () => {
mockProjectBy(
'alpine_3_12',
'gcc',
{ status: 200, body: fixtureGcc },
null
);
mockProjectBy('gcc', { status: 200, body: fixtureGcc });

const res = await getPkgReleases({
datasource,
Expand All @@ -213,12 +135,10 @@ describe(getName(__filename), () => {
});

it('returns correct version for multi-package project with different name', async () => {
mockProjectBy(
'debian_stable',
'pulseaudio-utils',
{ status: 200, body: fixturePulseaudio },
null
);
mockProjectBy('pulseaudio-utils', {
status: 200,
body: fixturePulseaudio,
});

const res = await getPkgReleases({
datasource,
Expand All @@ -238,12 +158,7 @@ describe(getName(__filename), () => {
];
const pkgsJSON = JSON.stringify(pkgs);

mockProjectBy(
'dummy',
'example',
{ status: 200, body: pkgsJSON },
{ status: 200, body: pkgsJSON }
);
mockProjectBy('example', { status: 200, body: pkgsJSON });

expect(
await getPkgReleases({
Expand Down
Loading

0 comments on commit e3ccc35

Please sign in to comment.