From 7272dd2d756ec7051b5e7c8e7433a853b26c1f0d Mon Sep 17 00:00:00 2001
From: Shingo Sato <shinsugar@gmail.com>
Date: Sat, 20 Jul 2024 00:46:44 +0900
Subject: [PATCH] fix(manager/circleci): optional jobs parameter (#30251)

---
 .../manager/circleci/__fixtures__/config4.yml       |  9 +++++++++
 lib/modules/manager/circleci/extract.spec.ts        | 13 +++++++++++++
 lib/modules/manager/circleci/extract.ts             |  2 +-
 lib/modules/manager/circleci/schema.ts              |  2 +-
 4 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 lib/modules/manager/circleci/__fixtures__/config4.yml

diff --git a/lib/modules/manager/circleci/__fixtures__/config4.yml b/lib/modules/manager/circleci/__fixtures__/config4.yml
new file mode 100644
index 0000000000..9f74c3fd85
--- /dev/null
+++ b/lib/modules/manager/circleci/__fixtures__/config4.yml
@@ -0,0 +1,9 @@
+version: 2.1
+
+orbs:
+  nodejs: circleci/node@5.2.0
+
+workflows:
+  Test:
+    jobs:
+      - nodejs/test
diff --git a/lib/modules/manager/circleci/extract.spec.ts b/lib/modules/manager/circleci/extract.spec.ts
index 827f791248..43443f18d1 100644
--- a/lib/modules/manager/circleci/extract.spec.ts
+++ b/lib/modules/manager/circleci/extract.spec.ts
@@ -4,6 +4,7 @@ import { extractPackageFile } from '.';
 const file1 = Fixtures.get('config.yml');
 const file2 = Fixtures.get('config2.yml');
 const file3 = Fixtures.get('config3.yml');
+const file4 = Fixtures.get('config4.yml');
 
 describe('modules/manager/circleci/extract', () => {
   describe('extractPackageFile()', () => {
@@ -65,5 +66,17 @@ describe('modules/manager/circleci/extract', () => {
         ),
       ).toBeNull();
     });
+
+    it('extracts orbs without jobs', () => {
+      const res = extractPackageFile(file4);
+      expect(res?.deps).toMatchObject([
+        {
+          depName: 'nodejs',
+          currentValue: '5.2.0',
+          datasource: 'orb',
+          depType: 'orb',
+        },
+      ]);
+    });
   });
 });
diff --git a/lib/modules/manager/circleci/extract.ts b/lib/modules/manager/circleci/extract.ts
index 4de5c6b58e..dd73d2ac04 100644
--- a/lib/modules/manager/circleci/extract.ts
+++ b/lib/modules/manager/circleci/extract.ts
@@ -30,7 +30,7 @@ export function extractPackageFile(
       });
     }
 
-    for (const job of Object.values(parsed.jobs)) {
+    for (const job of Object.values(parsed.jobs ?? {})) {
       for (const dockerElement of coerceArray(job.docker)) {
         deps.push({
           ...getDep(dockerElement.image),
diff --git a/lib/modules/manager/circleci/schema.ts b/lib/modules/manager/circleci/schema.ts
index 09c945bd11..2d6e831c65 100644
--- a/lib/modules/manager/circleci/schema.ts
+++ b/lib/modules/manager/circleci/schema.ts
@@ -10,6 +10,6 @@ export const CircleCiJob = z.object({
 
 export const CircleCiFile = z.object({
   aliases: z.array(CircleCiDocker).optional(),
-  jobs: z.record(z.string(), CircleCiJob),
+  jobs: z.record(z.string(), CircleCiJob).optional(),
   orbs: z.record(z.string()).optional(),
 });
-- 
GitLab