From 87b41a60e9a39e9273bd810ad12f8a394dd1781e Mon Sep 17 00:00:00 2001
From: timothycarambat <rambat1010@gmail.com>
Date: Thu, 16 May 2024 11:01:34 -0700
Subject: [PATCH] refactor spaceKey url pattern for custom domains

---
 .../utils/extensions/Confluence/index.js      | 22 +++++++++----------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/collector/utils/extensions/Confluence/index.js b/collector/utils/extensions/Confluence/index.js
index ff91773cb..b18ae3144 100644
--- a/collector/utils/extensions/Confluence/index.js
+++ b/collector/utils/extensions/Confluence/index.js
@@ -19,19 +19,17 @@ function validSpaceUrl(spaceUrl = "") {
     return { valid: true, result: atlassianMatch };
   }
 
-  // Custom Confluence URL match
-  const customPattern = new UrlPattern(
-    "https\\://(:subdomain.):domain.:tld/wiki/spaces/(:spaceKey)/*"
-  );
-  const customMatch = customPattern.match(spaceUrl);
-
-  // Custom "display" Confluence URL match
-  const customDisplayPattern = new UrlPattern(
-    "https\\://(:subdomain.):domain.:tld/display/(:spaceKey)/*"
-  );
-  const customDisplayMatch = customDisplayPattern.match(spaceUrl);
+  let customMatch = null;
+  [
+    "https\\://(:subdomain.):domain.:tld/wiki/spaces/(:spaceKey)/*", // Custom Confluence space
+    "https\\://(:subdomain.):domain.:tld/display/(:spaceKey)/*", // Custom Confluence space + Human-readable space tag.
+  ].forEach((matchPattern) => {
+    if (!!customMatch) return;
+    const pattern = new UrlPattern(matchPattern);
+    customMatch = pattern.match(spaceUrl);
+  });
 
-  if (customMatch || customDisplayMatch) {
+  if (customMatch) {
     customMatch.customDomain =
       (customMatch.subdomain ? `${customMatch.subdomain}.` : "") + //
       `${customMatch.domain}.${customMatch.tld}`;
-- 
GitLab