From 48e6aa4f8477f81895ca6eed22b39d6cfc3ccd32 Mon Sep 17 00:00:00 2001
From: Leonismoe <leonismoe@users.noreply.github.com>
Date: Mon, 24 Jun 2024 14:55:39 +0800
Subject: [PATCH] feat(datasource/custom): expose `tags` in result so that we
 can use `followTag` (#29806)

---
 lib/modules/datasource/custom/index.spec.ts | 43 +++++++++++++++++++++
 lib/modules/datasource/custom/schema.ts     |  1 +
 2 files changed, 44 insertions(+)

diff --git a/lib/modules/datasource/custom/index.spec.ts b/lib/modules/datasource/custom/index.spec.ts
index 5b997fa689..2d997c6b30 100644
--- a/lib/modules/datasource/custom/index.spec.ts
+++ b/lib/modules/datasource/custom/index.spec.ts
@@ -119,6 +119,49 @@ describe('modules/datasource/custom/index', () => {
       expect(result).toEqual(expected);
     });
 
+    it('return releases with tags and other optional fields for api directly exposing in renovate format', async () => {
+      const expected = {
+        releases: [
+          {
+            version: 'v1.0.0',
+          },
+        ],
+        tags: {
+          latest: 'v1.0.0',
+        },
+        sourceUrl: 'https://example.com/foo.git',
+        sourceDirectory: '/',
+        changelogUrl: 'https://example.com/foo/blob/main/CHANGELOG.md',
+        homepage: 'https://example.com/foo',
+      };
+      const content = {
+        releases: [
+          {
+            version: 'v1.0.0',
+          },
+        ],
+        tags: {
+          latest: 'v1.0.0',
+        },
+        sourceUrl: 'https://example.com/foo.git',
+        sourceDirectory: '/',
+        changelogUrl: 'https://example.com/foo/blob/main/CHANGELOG.md',
+        homepage: 'https://example.com/foo',
+        unknown: {},
+      };
+      httpMock.scope('https://example.com').get('/v1').reply(200, content);
+      const result = await getPkgReleases({
+        datasource: `${CustomDatasource.id}.foo`,
+        packageName: 'myPackage',
+        customDatasources: {
+          foo: {
+            defaultRegistryUrlTemplate: 'https://example.com/v1',
+          },
+        },
+      });
+      expect(result).toEqual(expected);
+    });
+
     it('return releases for plain text API directly exposing in Renovate format', async () => {
       const expected = {
         releases: [
diff --git a/lib/modules/datasource/custom/schema.ts b/lib/modules/datasource/custom/schema.ts
index 532d44b5a1..58a1df4f0e 100644
--- a/lib/modules/datasource/custom/schema.ts
+++ b/lib/modules/datasource/custom/schema.ts
@@ -20,6 +20,7 @@ export const ReleaseResultZodSchema = z.object({
         };
       }),
   ),
+  tags: z.record(z.string(), z.string()).optional(),
   sourceUrl: z.string().optional(),
   sourceDirectory: z.string().optional(),
   changelogUrl: z.string().optional(),
-- 
GitLab