From 12fec322762adbdd5e9234d7b32a959ce31e51eb Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Thu, 21 Dec 2023 23:41:41 +0545 Subject: [PATCH] feat(datasource/hex): extract deprecated versions (#26392) --- .../datasource/hex/__fixtures__/certifi.json | 7 ++++++- .../hex/__snapshots__/index.spec.ts.snap | 2 ++ lib/modules/datasource/hex/index.spec.ts | 13 +++++++++++++ lib/modules/datasource/hex/schema.ts | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/modules/datasource/hex/__fixtures__/certifi.json b/lib/modules/datasource/hex/__fixtures__/certifi.json index ae3248783ea01ab..4d52475d6f5c380 100644 --- a/lib/modules/datasource/hex/__fixtures__/certifi.json +++ b/lib/modules/datasource/hex/__fixtures__/certifi.json @@ -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" } diff --git a/lib/modules/datasource/hex/__snapshots__/index.spec.ts.snap b/lib/modules/datasource/hex/__snapshots__/index.spec.ts.snap index f1dba45a9e75582..4067953c19a138d 100644 --- a/lib/modules/datasource/hex/__snapshots__/index.spec.ts.snap +++ b/lib/modules/datasource/hex/__snapshots__/index.spec.ts.snap @@ -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", }, @@ -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", }, diff --git a/lib/modules/datasource/hex/index.spec.ts b/lib/modules/datasource/hex/index.spec.ts index 70556645629f5e0..cf9cbb9b565b5ed 100644 --- a/lib/modules/datasource/hex/index.spec.ts +++ b/lib/modules/datasource/hex/index.spec.ts @@ -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, { diff --git a/lib/modules/datasource/hex/schema.ts b/lib/modules/datasource/hex/schema.ts index b1015ae664d0656..fea85b0919da78c 100644 --- a/lib/modules/datasource/hex/schema.ts +++ b/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'; @@ -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( @@ -29,6 +39,10 @@ export const HexRelease = z release.releaseTimestamp = releaseTimestamp; } + if (is.plainObject(hexResponse.retirements?.[version])) { + release.isDeprecated = true; + } + return release; }, );