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

feat(datasource/cpan): populate latest tag #32677

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
12 changes: 11 additions & 1 deletion lib/modules/datasource/cpan/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ describe('modules/datasource/cpan/index', () => {
(body) =>
body.query.filtered.filter.and[0].term['module.name'] === 'Plack',
)
.reply(200, Fixtures.get('Plack.json'));
.reply(200, Fixtures.get('Plack.json'))
.get('/v1/module/Plack')
.reply(200, {
module: [
{
name: 'Plack',
version: '1.0048',
},
],
});
const res = await getPkgReleases({
datasource: CpanDatasource.id,
packageName: 'Plack',
Expand All @@ -86,6 +95,7 @@ describe('modules/datasource/cpan/index', () => {
releaseTimestamp: '2020-11-30T00:21:36.000Z',
version: '1.0048',
});
expect(res?.tags?.latest).toBe('1.0048');
});
});
});
20 changes: 20 additions & 0 deletions lib/modules/datasource/cpan/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { logger } from '../../../logger';
import { cache } from '../../../util/cache/package/decorator';
import { joinUrlParts } from '../../../util/url';
import * as perlVersioning from '../../versioning/perl';
Expand Down Expand Up @@ -107,6 +108,25 @@
changelogUrl: `https://metacpan.org/dist/${latestDistribution}/changes`,
homepage: `https://metacpan.org/pod/${packageName}`,
};

try {
const latestVersionUrl = joinUrlParts(
registryUrl,
'v1/module/',
packageName,
);
const latestVersionRes = (
await this.http.getJson<MetaCpanApiFile>(latestVersionUrl)
).body;
const latestVersion = latestVersionRes?.module?.[0]?.version;

if (latestVersion) {
result.tags ??= {};
result.tags.latest ??= latestVersion;
}
} catch {
logger.debug(`Error while fetching latest tag for ${packageName}.`);

Check warning on line 128 in lib/modules/datasource/cpan/index.ts

View check run for this annotation

Codecov / codecov/patch

lib/modules/datasource/cpan/index.ts#L128

Added line #L128 was not covered by tests
}
}
}
return result;
Expand Down
Loading