From 60eba68eb3724a718e030589ed84aaf4c466a58b Mon Sep 17 00:00:00 2001
From: Jesse Rosenberger <git@jro.cc>
Date: Sun, 11 Apr 2021 09:04:42 +0300
Subject: [PATCH] fix(circleci): Expect whitespace/comments during CircleCI Orb
 parsing (#9486)

---
 lib/manager/circleci/__fixtures__/config2.yml |  6 ++++++
 lib/manager/circleci/extract.ts               | 15 +++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/lib/manager/circleci/__fixtures__/config2.yml b/lib/manager/circleci/__fixtures__/config2.yml
index e69a586240..cf55b2aebc 100644
--- a/lib/manager/circleci/__fixtures__/config2.yml
+++ b/lib/manager/circleci/__fixtures__/config2.yml
@@ -1,8 +1,14 @@
 version: 2.1
 
+# There are blank lines and comments in this orbs section intentionally!
 orbs:
   release-workflows: hutson/library-release-workflows@4.1.0
+  # Comments help me understand my work.
+  # The next line is intentionally just whitespace!
+  
   no-version: abc/def
+
+  # Comments help me understand my work.
   volatile: zzz/zzz@volatile
 
 test_plan: &test_plan
diff --git a/lib/manager/circleci/extract.ts b/lib/manager/circleci/extract.ts
index 900105cc49..f71a48a3b7 100644
--- a/lib/manager/circleci/extract.ts
+++ b/lib/manager/circleci/extract.ts
@@ -13,15 +13,22 @@ export function extractPackageFile(content: string): PackageFile | null {
       const orbs = /^\s*orbs:\s*$/.exec(line);
       if (orbs) {
         logger.trace(`Matched orbs on line ${lineNumber}`);
-        let foundOrb: boolean;
+        let foundOrbOrNoop: boolean;
         do {
-          foundOrb = false;
+          foundOrbOrNoop = false;
           const orbLine = lines[lineNumber + 1];
           logger.trace(`orbLine: "${orbLine}"`);
+          const yamlNoop = /^\s*(#|$)/.exec(orbLine);
+          if (yamlNoop) {
+            logger.debug('orbNoop');
+            foundOrbOrNoop = true;
+            lineNumber += 1;
+            continue; // eslint-disable-line no-continue
+          }
           const orbMatch = /^\s+([^:]+):\s(.+)$/.exec(orbLine);
           if (orbMatch) {
             logger.trace('orbMatch');
-            foundOrb = true;
+            foundOrbOrNoop = true;
             lineNumber += 1;
             const depName = orbMatch[1];
             const [orbName, currentValue] = orbMatch[2].split('@');
@@ -37,7 +44,7 @@ export function extractPackageFile(content: string): PackageFile | null {
             };
             deps.push(dep);
           }
-        } while (foundOrb);
+        } while (foundOrbOrNoop);
       }
       const match = /^\s*-? image:\s*'?"?([^\s'"]+)'?"?\s*$/.exec(line);
       if (match) {
-- 
GitLab