Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datasource/packagist): Revert "refactor(composer): Simplify Packagist lookups" #19824

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 5 additions & 30 deletions lib/modules/datasource/packagist/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ describe('modules/datasource/packagist/index', () => {
.scope('https://composer.renovatebot.com')
.get('/packages.json')
.replyWithError({ code: 'ETIMEDOUT' });
httpMock
.scope(baseUrl)
.get('/p2/vendor/package-name2.json')
.reply(200)
.get('/p2/vendor/package-name2~dev.json')
.reply(200);
httpMock.scope(baseUrl).get('/p2/vendor/package-name2.json').reply(200);
const res = await getPkgReleases({
...config,
datasource,
Expand All @@ -102,12 +97,7 @@ describe('modules/datasource/packagist/index', () => {
.scope('https://composer.renovatebot.com')
.get('/packages.json')
.reply(403);
httpMock
.scope(baseUrl)
.get('/p2/vendor/package-name.json')
.reply(200)
.get('/p2/vendor/package-name~dev.json')
.reply(200);
httpMock.scope(baseUrl).get('/p2/vendor/package-name.json').reply(200);
const res = await getPkgReleases({
...config,
datasource,
Expand All @@ -122,12 +112,7 @@ describe('modules/datasource/packagist/index', () => {
.scope('https://composer.renovatebot.com')
.get('/packages.json')
.reply(404);
httpMock
.scope(baseUrl)
.get('/p2/drewm/mailchimp-api.json')
.reply(200)
.get('/p2/drewm/mailchimp-api~dev.json')
.reply(200);
httpMock.scope(baseUrl).get('/p2/drewm/mailchimp-api.json').reply(200);
const res = await getPkgReleases({
...config,
datasource,
Expand Down Expand Up @@ -281,12 +266,7 @@ describe('modules/datasource/packagist/index', () => {
'/p/providers-2018-09$14346045d7a7261cb3a12a6b7a1a7c4151982530347b115e5e277d879cad1942.json'
)
.reply(200, fileJson);
httpMock
.scope(baseUrl)
.get('/p2/some/other.json')
.reply(200, beytJson)
.get('/p2/some/other~dev.json')
.reply(200, beytJson);
httpMock.scope(baseUrl).get('/p2/some/other.json').reply(200, beytJson);
const res = await getPkgReleases({
...config,
datasource,
Expand Down Expand Up @@ -377,12 +357,7 @@ describe('modules/datasource/packagist/index', () => {
.scope('https://composer.renovatebot.com')
.get('/packages.json')
.reply(200, packagesJson);
httpMock
.scope(baseUrl)
.get('/p2/some/other.json')
.reply(200, beytJson)
.get('/p2/some/other~dev.json')
.reply(200, beytJson);
httpMock.scope(baseUrl).get('/p2/some/other.json').reply(200, beytJson);
const res = await getPkgReleases({
...config,
datasource,
Expand Down
40 changes: 28 additions & 12 deletions lib/modules/datasource/packagist/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import URL from 'url';
import { logger } from '../../../logger';
import { ExternalHostError } from '../../../types/errors/external-host-error';
import * as packageCache from '../../../util/cache/package';
import { cache } from '../../../util/cache/package/decorator';
import * as hostRules from '../../../util/host-rules';
import type { HttpOptions } from '../../../util/http/types';
Expand All @@ -10,7 +11,6 @@ import { ensureTrailingSlash, joinUrlParts } from '../../../util/url';
import * as composerVersioning from '../../versioning/composer';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, ReleaseResult } from '../types';
import * as schema from './schema';
import type {
AllPackages,
PackageMeta,
Expand Down Expand Up @@ -199,19 +199,35 @@ export class PackagistDatasource extends Datasource {
return allPackages;
}

@cache({
namespace: `datasource-${PackagistDatasource.id}-org`,
key: (regUrl: string) => regUrl,
ttlMinutes: 10,
})
async packagistOrgLookup(name: string): Promise<ReleaseResult | null> {
const regUrl = 'https://packagist.org';
const pkgUrl = joinUrlParts(regUrl, `/p2/${name}.json`);
const devUrl = joinUrlParts(regUrl, `/p2/${name}~dev.json`);
const results = await p.map([pkgUrl, devUrl], (url) =>
this.http.getJson(url).then(({ body }) => body)
const cacheNamespace = 'datasource-packagist-org';
const cachedResult = await packageCache.get<ReleaseResult>(
cacheNamespace,
name
);
return schema.ComposerV2ReleaseResult.parse(results);
// istanbul ignore if
if (cachedResult) {
return cachedResult;
}
let dep: ReleaseResult | null = null;
const regUrl = 'https://packagist.org';
const pkgUrl = [
joinUrlParts(regUrl, `/p2/${name}.json`),
joinUrlParts(regUrl, `/p2/${name}~dev.json`),
];
// TODO: fix types (#9610)
let res = (await this.http.getJson<any>(pkgUrl[0])).body.packages[name];
res = [
...res,
...(await this.http.getJson<any>(pkgUrl[1])).body.packages[name],
];
if (res) {
dep = PackagistDatasource.extractDepReleases(res);
logger.trace({ dep }, 'dep');
}
const cacheMinutes = 10;
await packageCache.set(cacheNamespace, name, dep, cacheMinutes);
return dep;
}

public override async getReleases({
Expand Down
67 changes: 0 additions & 67 deletions lib/modules/datasource/packagist/schema.ts

This file was deleted.