Skip to content

Commit

Permalink
feat(packagist): Extract PHP constraints (#19875)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
zharinov and rarkins committed Jan 17, 2023
1 parent bf6ac7d commit ef174ce
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
42 changes: 40 additions & 2 deletions lib/modules/datasource/packagist/schema.spec.ts
Expand Up @@ -144,6 +144,32 @@ describe('modules/datasource/packagist/schema', () => {
})
).toEqual([{ version: '1.2.3' }]);
});

it('expands minified fields', () => {
expect(
parsePackagesResponse('foo/bar', {
packages: {
'foo/bar': [
{ version: '3.3.3', require: { php: '^8.0' } },
{ version: '2.2.2' },
{ version: '1.1.1' },
{ version: '0.0.4', require: { php: '^7.0' } },
{ version: '0.0.3' },
{ version: '0.0.2', require: '__unset' },
{ version: '0.0.1' },
],
},
})
).toEqual([
{ version: '3.3.3', require: { php: '^8.0' } },
{ version: '2.2.2', require: { php: '^8.0' } },
{ version: '1.1.1', require: { php: '^8.0' } },
{ version: '0.0.4', require: { php: '^7.0' } },
{ version: '0.0.3', require: { php: '^7.0' } },
{ version: '0.0.2' },
{ version: '0.0.1' },
] satisfies ComposerRelease[]);
});
});

describe('parsePackagesResponses', () => {
Expand All @@ -164,6 +190,7 @@ describe('modules/datasource/packagist/schema', () => {
time: '111',
homepage: 'https://example.com/1',
source: { url: 'git@example.com:foo/bar-1' },
require: { php: '^8.0' },
},
],
'baz/qux': [
Expand All @@ -184,6 +211,7 @@ describe('modules/datasource/packagist/schema', () => {
time: '333',
homepage: 'https://example.com/3',
source: { url: 'git@example.com:foo/bar-3' },
require: { php: '^7.0' },
},
],
'baz/qux': [
Expand All @@ -201,8 +229,18 @@ describe('modules/datasource/packagist/schema', () => {
homepage: 'https://example.com/1',
sourceUrl: 'git@example.com:foo/bar-1',
releases: [
{ version: '1.1.1', gitRef: 'v1.1.1', releaseTimestamp: '111' },
{ version: '3.3.3', gitRef: 'v3.3.3', releaseTimestamp: '333' },
{
version: '1.1.1',
gitRef: 'v1.1.1',
releaseTimestamp: '111',
constraints: { php: ['^8.0'] },
},
{
version: '3.3.3',
gitRef: 'v3.3.3',
releaseTimestamp: '333',
constraints: { php: ['^7.0'] },
},
],
} satisfies ReleaseResult);
});
Expand Down
10 changes: 10 additions & 0 deletions lib/modules/datasource/packagist/schema.ts
Expand Up @@ -54,6 +54,12 @@ export const ComposerRelease = z
.nullable()
.catch(null),
time: z.string().nullable().catch(null),
require: z
.object({
php: z.string(),
})
.nullable()
.catch(null),
})
.partial()
);
Expand Down Expand Up @@ -106,6 +112,10 @@ export function parsePackagesResponses(
dep.releaseTimestamp = composerRelease.time;
}

if (composerRelease.require?.php) {
dep.constraints = { php: [composerRelease.require.php] };
}

releases.push(dep);

if (!homepage && composerRelease.homepage) {
Expand Down

0 comments on commit ef174ce

Please sign in to comment.