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/hex): extract deprecated versions #26392

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
7 changes: 6 additions & 1 deletion lib/modules/datasource/hex/__fixtures__/certifi.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@
}
],
"repository": "hexpm",
"retirements": {},
"retirements": {
"0.1.1": {
"message": "Used for testing",
"reason": "Not really retired"
}
},
"updated_at": "2020-03-04T14:54:16.279054Z",
"url": "https://hex.pm/api/packages/certifi"
}
2 changes: 2 additions & 0 deletions lib/modules/datasource/hex/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`modules/datasource/hex/index getReleases process public repo without au
"registryUrl": "https://hex.pm/",
"releases": [
{
"isDeprecated": true,
"releaseTimestamp": "2015-09-10T13:58:55.620Z",
"version": "0.1.1",
},
Expand Down Expand Up @@ -112,6 +113,7 @@ exports[`modules/datasource/hex/index getReleases processes real data 1`] = `
"registryUrl": "https://hex.pm/",
"releases": [
{
"isDeprecated": true,
"releaseTimestamp": "2015-09-10T13:58:55.620Z",
"version": "0.1.1",
},
Expand Down
13 changes: 13 additions & 0 deletions lib/modules/datasource/hex/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ describe('modules/datasource/hex/index', () => {
expect(res).toBeDefined();
});

it('extracts depreceated info', async () => {
httpMock
.scope(baseUrl)
.get('/packages/certifi')
.reply(200, certifiResponse);
hostRules.find.mockReturnValueOnce({});
const res = await getPkgReleases({
datasource,
packageName: 'certifi',
});
expect(res?.releases.some((rel) => rel.isDeprecated)).toBeTrue();
});

it('processes a private repo with auth', async () => {
httpMock
.scope(baseUrl, {
Expand Down
14 changes: 14 additions & 0 deletions lib/modules/datasource/hex/schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import is from '@sindresorhus/is';
import { z } from 'zod';
import { LooseArray } from '../../../util/schema-utils';
import type { Release, ReleaseResult } from '../types';
Expand All @@ -19,6 +20,15 @@ export const HexRelease = z
inserted_at: z.string().optional(),
}),
).refine((releases) => releases.length > 0, 'No releases found'),
retirements: z
.record(
z.string(),
z.object({
message: z.string(),
reason: z.string(),
}),
)
.optional(),
})
.transform((hexResponse): ReleaseResult => {
const releases: Release[] = hexResponse.releases.map(
Expand All @@ -29,6 +39,10 @@ export const HexRelease = z
release.releaseTimestamp = releaseTimestamp;
}

if (is.plainObject(hexResponse.retirements?.[version])) {
release.isDeprecated = true;
}

return release;
},
);
Expand Down