From 6b4d5fcdbb0502c71ebe9fc9f63e6ed987e6fe3c Mon Sep 17 00:00:00 2001
From: RahulGautamSingh <rahultesnik@gmail.com>
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 ae3248783e..4d52475d6f 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 f1dba45a9e..4067953c19 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 7055664562..cf9cbb9b56 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 b1015ae664..fea85b0919 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;
       },
     );
-- 
GitLab