Skip to content

Commit

Permalink
feat(datasource/hex): extract deprecated versions (#26392)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed Dec 21, 2023
1 parent 8b24dde commit 6b4d5fc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/modules/datasource/hex/__fixtures__/certifi.json
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
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
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
@@ -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

0 comments on commit 6b4d5fc

Please sign in to comment.