mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
refactor: remove semver dependency from github datasource
Instead, perform isVersion filter in lookup
This commit is contained in:
parent
468349d8f4
commit
05260a5b16
4 changed files with 14 additions and 9 deletions
|
@ -1,5 +1,4 @@
|
|||
const ghGot = require('../platform/github/gh-got-wrapper');
|
||||
const versioning = require('../versioning');
|
||||
|
||||
module.exports = {
|
||||
getDependency,
|
||||
|
@ -48,10 +47,8 @@ async function getDependency(repo, options = {}) {
|
|||
return null;
|
||||
}
|
||||
// Filter by semver if no versionScheme provided
|
||||
const { isVersion } = versioning(options.versionScheme || 'semver');
|
||||
versions = versions.filter(version => isVersion(version));
|
||||
if (options.clean === 'true') {
|
||||
versions = versions.map(version => version.replace(/^v/, ''));
|
||||
versions = versions.map(version => version.replace(/^v(\d)/, '$1'));
|
||||
}
|
||||
const dependency = {
|
||||
repositoryUrl: 'https://github.com/' + repo,
|
||||
|
|
|
@ -19,6 +19,7 @@ async function lookupUpdates(config) {
|
|||
getMinor,
|
||||
isGreaterThan,
|
||||
isRange,
|
||||
isVersion,
|
||||
matches,
|
||||
getNewValue,
|
||||
} = versioning(config.versionScheme);
|
||||
|
@ -54,7 +55,10 @@ async function lookupUpdates(config) {
|
|||
// TODO: return an object
|
||||
return [result];
|
||||
}
|
||||
const allVersions = Object.keys(dependency.versions);
|
||||
// Filter out any results from datasource that don't comply with our versioning scheme
|
||||
const allVersions = Object.keys(dependency.versions).filter(v =>
|
||||
isVersion(v)
|
||||
);
|
||||
// istanbul ignore if
|
||||
if (allVersions.length === 0) {
|
||||
const message = `No versions returned from registry for this package`;
|
||||
|
|
|
@ -6,6 +6,8 @@ Object {
|
|||
"versions": Object {
|
||||
"1.0.0": Object {},
|
||||
"1.1.0": Object {},
|
||||
"a": Object {},
|
||||
"v": Object {},
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
@ -15,6 +17,8 @@ Object {
|
|||
"repositoryUrl": "https://github.com/some/dep",
|
||||
"versions": Object {
|
||||
"1.0.0": Object {},
|
||||
"a": Object {},
|
||||
"v": Object {},
|
||||
"v1.1.0": Object {},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -9,27 +9,27 @@ describe('datasource/github', () => {
|
|||
it('returns cleaned tags', async () => {
|
||||
const body = [
|
||||
{ ref: 'refs/tags/a' },
|
||||
{ ref: 'refs/tags/b' },
|
||||
{ ref: 'refs/tags/v' },
|
||||
{ ref: 'refs/tags/1.0.0' },
|
||||
{ ref: 'refs/tags/v1.1.0' },
|
||||
];
|
||||
ghGot.mockReturnValueOnce({ headers: {}, body });
|
||||
const res = await github.getDependency('some/dep', { clean: 'true' });
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(Object.keys(res.versions)).toHaveLength(2);
|
||||
expect(Object.keys(res.versions)).toHaveLength(4);
|
||||
expect(res.versions['1.1.0']).toBeDefined();
|
||||
});
|
||||
it('returns releases', async () => {
|
||||
const body = [
|
||||
{ tag_name: 'a' },
|
||||
{ tag_name: 'b' },
|
||||
{ tag_name: 'v' },
|
||||
{ tag_name: '1.0.0' },
|
||||
{ tag_name: 'v1.1.0' },
|
||||
];
|
||||
ghGot.mockReturnValueOnce({ headers: {}, body });
|
||||
const res = await github.getDependency('some/dep', { ref: 'release' });
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(Object.keys(res.versions)).toHaveLength(2);
|
||||
expect(Object.keys(res.versions)).toHaveLength(4);
|
||||
expect(res.versions['v1.1.0']).toBeDefined();
|
||||
});
|
||||
it('returns null for invalid ref', async () => {
|
||||
|
|
Loading…
Reference in a new issue