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

refactor(packagist): Remove unnecessary wrapper method #19818

Merged
merged 2 commits into from
Jan 13, 2023
Merged
Changes from 1 commit
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
59 changes: 28 additions & 31 deletions lib/modules/datasource/packagist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ export class PackagistDatasource extends Datasource {

override readonly registryStrategy = 'hunt';

public override getReleases({
packageName,
registryUrl,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
logger.trace(`getReleases(${packageName})`);
// istanbul ignore if
if (!registryUrl) {
return Promise.resolve(null);
}
return this.packageLookup(registryUrl, packageName);
}

// We calculate auth at this datasource layer so that we can know whether it's safe to cache or not
private static getHostOpts(url: string): HttpOptions {
let opts: HttpOptions = {};
Expand Down Expand Up @@ -226,16 +214,23 @@ export class PackagistDatasource extends Datasource {
return schema.ComposerV2ReleaseResult.parse(results);
}

private async packageLookup(
regUrl: string,
name: string
): Promise<ReleaseResult | null> {
public override async getReleases({
packageName,
registryUrl,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
logger.trace(`getReleases(${packageName})`);

// istanbul ignore if
if (!registryUrl) {
return null;
}

try {
if (regUrl === 'https://packagist.org') {
const packagistResult = await this.packagistOrgLookup(name);
if (registryUrl === 'https://packagist.org') {
const packagistResult = await this.packagistOrgLookup(packageName);
return packagistResult;
}
const allPackages = await this.getAllPackages(regUrl);
const allPackages = await this.getAllPackages(registryUrl);
// istanbul ignore if: needs test
if (!allPackages) {
return null;
Expand All @@ -247,33 +242,35 @@ export class PackagistDatasource extends Datasource {
providerPackages,
includesPackages,
} = allPackages;
if (packages?.[name]) {
const dep = PackagistDatasource.extractDepReleases(packages[name]);
if (packages?.[packageName]) {
const dep = PackagistDatasource.extractDepReleases(
packages[packageName]
);
return dep;
}
if (includesPackages?.[name]) {
return includesPackages[name];
if (includesPackages?.[packageName]) {
return includesPackages[packageName];
}
let pkgUrl: string;
if (name in providerPackages) {
if (packageName in providerPackages) {
pkgUrl = URL.resolve(
regUrl,
registryUrl,
providersUrl!
.replace('%package%', name)
.replace('%hash%', providerPackages[name])
.replace('%package%', packageName)
.replace('%hash%', providerPackages[packageName])
);
} else if (providersLazyUrl) {
pkgUrl = URL.resolve(
regUrl,
providersLazyUrl.replace('%package%', name)
registryUrl,
providersLazyUrl.replace('%package%', packageName)
);
} else {
return null;
}
const opts = PackagistDatasource.getHostOpts(regUrl);
const opts = PackagistDatasource.getHostOpts(registryUrl);
// TODO: fix types (#9610)
const versions = (await this.http.getJson<any>(pkgUrl, opts)).body
.packages[name];
.packages[packageName];
const dep = PackagistDatasource.extractDepReleases(versions);
logger.trace({ dep }, 'dep');
return dep;
Expand Down