Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(datasource): return null instead of empty releases
  • Loading branch information
rarkins committed Jun 19, 2020
1 parent c8cc375 commit 508bd47
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
6 changes: 4 additions & 2 deletions lib/datasource/go/index.spec.ts
Expand Up @@ -146,12 +146,14 @@ describe('datasource/go', () => {
{ datasource, depName: 'gopkg.in/x/text' },
{ datasource, depName: 'gopkg.in/x' },
];
const githubRes = { releases: [1, 2] } as any;
const githubRes = {
releases: [],
} as any;
for (const pkg of packages) {
github.getReleases.mockResolvedValueOnce(
partial<ReleaseResult>(githubRes)
);
expect(await getPkgReleases(pkg)).toEqual(githubRes);
expect(await getPkgReleases(pkg)).toBeNull();
}
expect(github.getReleases.mock.calls).toMatchSnapshot();
});
Expand Down
5 changes: 4 additions & 1 deletion lib/datasource/index.ts
Expand Up @@ -49,10 +49,13 @@ async function fetchReleases(
}
const datasource = await load(datasourceName);
const registryUrls = resolveRegistryUrls(datasource, config.registryUrls);
const dep = await datasource.getReleases({
let dep = await datasource.getReleases({
...config,
registryUrls,
});
if (!(dep && dep.releases.length)) {
dep = null;
}
addMetaData(dep, datasourceName, config.lookupName);
return dep;
}
Expand Down
16 changes: 1 addition & 15 deletions lib/datasource/pypi/__snapshots__/index.spec.ts.snap
@@ -1,15 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`datasource/pypi getReleases find url from project_urls 1`] = `
Object {
"changelogUrl": "https://github.com/Flexget/wiki/blob/master/ChangeLog.md",
"homepage": "https://flexget.com",
"releases": Array [],
"sourceUrl": "https://github.com/Flexget/Flexget",
}
`;

exports[`datasource/pypi getReleases find url from project_urls 2`] = `
Array [
Object {
"headers": Object {
Expand Down Expand Up @@ -298,12 +289,7 @@ Array [
]
`;

exports[`datasource/pypi getReleases returns non-github home_page 1`] = `
Object {
"homepage": "https://microsoft.com",
"releases": Array [],
}
`;
exports[`datasource/pypi getReleases returns non-github home_page 1`] = `"https://microsoft.com"`;

exports[`datasource/pypi getReleases returns non-github home_page 2`] = `
Array [
Expand Down
19 changes: 12 additions & 7 deletions lib/datasource/pypi/index.spec.ts
Expand Up @@ -124,16 +124,19 @@ describe('datasource/pypi', () => {
.scope(baseUrl)
.get('/something/json')
.reply(200, {
...JSON.parse(res1),
info: {
name: 'something',
home_page: 'https://microsoft.com',
},
});
expect(
await getPkgReleases({
datasource,
depName: 'something',
})
(
await getPkgReleases({
datasource,
depName: 'something',
})
).homepage
).toMatchSnapshot();
expect(httpMock.getTrace()).toMatchSnapshot();
});
Expand All @@ -149,14 +152,16 @@ describe('datasource/pypi', () => {
Repository: 'https://github.com/Flexget/Flexget',
},
};
httpMock.scope(baseUrl).get('/flexget/json').reply(200, { info });
httpMock
.scope(baseUrl)
.get('/flexget/json')
.reply(200, { ...JSON.parse(res1), info });
const result = await getPkgReleases({
datasource,
depName: 'flexget',
});
expect(result.sourceUrl).toBe(info.project_urls.Repository);
expect(result.changelogUrl).toBe(info.project_urls.changelog);
expect(result).toMatchSnapshot();
expect(httpMock.getTrace()).toMatchSnapshot();
});
it('returns null if mismatched name', async () => {
Expand Down Expand Up @@ -310,7 +315,7 @@ describe('datasource/pypi', () => {
compatibility: { python: '2.7' },
depName: 'dj-database-url',
})
).toEqual({ releases: [] });
).toBeNull();
});
});
});

0 comments on commit 508bd47

Please sign in to comment.