mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 23:16:26 +00:00
feat(composer): lazy repository url (#6982)
This commit is contained in:
parent
43b2a2390d
commit
54cf4c1253
3 changed files with 99 additions and 7 deletions
|
@ -505,6 +505,47 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`datasource/packagist getReleases supports lazy repositories 1`] = `
|
||||
Object {
|
||||
"name": "guzzlehttp/guzzle",
|
||||
"releases": Array [
|
||||
Object {
|
||||
"gitRef": "5.3.4",
|
||||
"version": "5.3.4",
|
||||
},
|
||||
Object {
|
||||
"gitRef": "7.0.0-beta.1",
|
||||
"version": "7.0.0-beta.1",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`datasource/packagist getReleases supports lazy repositories 2`] = `
|
||||
Array [
|
||||
Object {
|
||||
"headers": Object {
|
||||
"accept": "application/json",
|
||||
"accept-encoding": "gzip, deflate",
|
||||
"host": "composer.renovatebot.com",
|
||||
"user-agent": "https://github.com/renovatebot/renovate",
|
||||
},
|
||||
"method": "GET",
|
||||
"url": "https://composer.renovatebot.com/composer/lazy/packages.json",
|
||||
},
|
||||
Object {
|
||||
"headers": Object {
|
||||
"accept": "application/json",
|
||||
"accept-encoding": "gzip, deflate",
|
||||
"host": "composer.renovatebot.com",
|
||||
"user-agent": "https://github.com/renovatebot/renovate",
|
||||
},
|
||||
"method": "GET",
|
||||
"url": "https://composer.renovatebot.com/composer/lazy/p/guzzlehttp/guzzle.json",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`datasource/packagist getReleases supports plain packages 1`] = `
|
||||
Object {
|
||||
"name": "vendor/package-name",
|
||||
|
|
|
@ -153,6 +153,45 @@ describe('datasource/packagist', () => {
|
|||
expect(res).not.toBeNull();
|
||||
expect(httpMock.getTrace()).toMatchSnapshot();
|
||||
});
|
||||
it('supports lazy repositories', async () => {
|
||||
const packagesJson = {
|
||||
packages: [],
|
||||
'providers-lazy-url':
|
||||
'https://composer.renovatebot.com/composer/lazy/p/%package%.json',
|
||||
};
|
||||
config = {
|
||||
registryUrls: ['https://composer.renovatebot.com/composer/lazy'],
|
||||
};
|
||||
const fileJson = {
|
||||
packages: {
|
||||
'guzzlehttp/guzzle': {
|
||||
'5.3.4': {
|
||||
name: 'guzzlehttp/guzzle',
|
||||
version: '5.3.4',
|
||||
},
|
||||
'7.0.0-beta.1': {
|
||||
name: 'guzzlehttp/guzzle',
|
||||
version: '7.0.0-beta.1',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
httpMock
|
||||
.scope('https://composer.renovatebot.com')
|
||||
.get('/composer/lazy/packages.json')
|
||||
.reply(200, packagesJson)
|
||||
.get('/composer/lazy/p/guzzlehttp/guzzle.json')
|
||||
.reply(200, fileJson);
|
||||
const res = await getPkgReleases({
|
||||
...config,
|
||||
datasource,
|
||||
versioning,
|
||||
depName: 'guzzlehttp/guzzle',
|
||||
});
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(res).not.toBeNull();
|
||||
expect(httpMock.getTrace()).toMatchSnapshot();
|
||||
});
|
||||
it('supports provider-includes', async () => {
|
||||
const packagesJson = {
|
||||
packages: [],
|
||||
|
|
|
@ -44,6 +44,7 @@ interface RegistryMeta {
|
|||
files?: RegistryFile[];
|
||||
providerPackages: Record<string, string>;
|
||||
providersUrl?: string;
|
||||
providersLazyUrl?: string;
|
||||
includesFiles?: RegistryFile[];
|
||||
packages?: Record<string, RegistryFile>;
|
||||
}
|
||||
|
@ -69,6 +70,9 @@ async function getRegistryMeta(regUrl: string): Promise<RegistryMeta | null> {
|
|||
if (res['providers-url']) {
|
||||
meta.providersUrl = res['providers-url'];
|
||||
}
|
||||
if (res['providers-lazy-url']) {
|
||||
meta.providersLazyUrl = res['providers-lazy-url'];
|
||||
}
|
||||
if (res['provider-includes']) {
|
||||
meta.files = [];
|
||||
for (const [key, val] of Object.entries(res['provider-includes'])) {
|
||||
|
@ -148,6 +152,7 @@ function extractDepReleases(versions: RegistryFile): ReleaseResult {
|
|||
interface AllPackages {
|
||||
packages: Record<string, RegistryFile>;
|
||||
providersUrl: string;
|
||||
providersLazyUrl: string;
|
||||
providerPackages: Record<string, string>;
|
||||
|
||||
includesPackages: Record<string, ReleaseResult>;
|
||||
|
@ -158,6 +163,7 @@ async function getAllPackages(regUrl: string): Promise<AllPackages | null> {
|
|||
const {
|
||||
packages,
|
||||
providersUrl,
|
||||
providersLazyUrl,
|
||||
files,
|
||||
includesFiles,
|
||||
providerPackages,
|
||||
|
@ -189,6 +195,7 @@ async function getAllPackages(regUrl: string): Promise<AllPackages | null> {
|
|||
const allPackages: AllPackages = {
|
||||
packages,
|
||||
providersUrl,
|
||||
providersLazyUrl,
|
||||
providerPackages,
|
||||
includesPackages,
|
||||
};
|
||||
|
@ -245,6 +252,7 @@ async function packageLookup(
|
|||
const {
|
||||
packages,
|
||||
providersUrl,
|
||||
providersLazyUrl,
|
||||
providerPackages,
|
||||
includesPackages,
|
||||
} = allPackages;
|
||||
|
@ -256,15 +264,19 @@ async function packageLookup(
|
|||
if (includesPackages?.[name]) {
|
||||
return includesPackages[name];
|
||||
}
|
||||
if (!providerPackages?.[name]) {
|
||||
let pkgUrl;
|
||||
if (providerPackages?.[name]) {
|
||||
pkgUrl = URL.resolve(
|
||||
regUrl,
|
||||
providersUrl
|
||||
.replace('%package%', name)
|
||||
.replace('%hash%', providerPackages[name])
|
||||
);
|
||||
} else if (providersLazyUrl) {
|
||||
pkgUrl = URL.resolve(regUrl, providersLazyUrl.replace('%package%', name));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
const pkgUrl = URL.resolve(
|
||||
regUrl,
|
||||
providersUrl
|
||||
.replace('%package%', name)
|
||||
.replace('%hash%', providerPackages[name])
|
||||
);
|
||||
const opts = getHostOpts(regUrl);
|
||||
// TODO: fix types
|
||||
const versions = (await http.getJson<any>(pkgUrl, opts)).body.packages[
|
||||
|
|
Loading…
Reference in a new issue