From 60c67c5fbb3b9249c620816e14813f44a629f779 Mon Sep 17 00:00:00 2001
From: Martin Lowe <martin.lowe@eclipse-foundation.org>
Date: Tue, 27 May 2025 16:04:15 -0400
Subject: [PATCH 1/3] feat: add support for private repository fetches via
 build env var

Resolves #10
---
 repos.yaml   |  4 ++++
 src/index.js | 12 +++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/repos.yaml b/repos.yaml
index aebbfeb..d672a68 100644
--- a/repos.yaml
+++ b/repos.yaml
@@ -50,3 +50,7 @@ specs:
   - name: "eclipsefdn-info-api"
     displayName: Info API
     location: "https://gitlab.eclipse.org/eclipsefdn/it/api/eclipsefdn-info-api/-/raw/main/spec/openapi.yaml"
+  - name: eclipse-projects-api
+    displayName: Projects API
+    location: "https://gitlab.eclipse.org/api/v4/projects/1641/repository/files/spec%2Fopenapi%2Eyaml/raw"
+    isPrivate: true
diff --git a/src/index.js b/src/index.js
index a96abc2..435bd79 100644
--- a/src/index.js
+++ b/src/index.js
@@ -24,6 +24,7 @@ const URL_REGEX = new RegExp('^https?://(?:[^./]+.){1,3}.[a-z]{2,3}(/[^/]+)*.[a-
 const TEMP_DIR_NAME = 'tmp';
 // the const to hold the generated spec data to be output for Hugo builds
 const artificialSpecData = { items: [] };
+const PRIVATE_TOKEN = process.env.GITLAB_API_TOKEN;
 
 /**
  * Pull an external/remote spec using fetch and write it to the file system for further processing.
@@ -31,14 +32,18 @@ const artificialSpecData = { items: [] };
  * @param {*} externalLocation the URL for the raw openapi spec file.
  * @param {*} localPath the location where the downloaded spec should be saved
  */
-async function pullExternalSpec(externalLocation, localPath) {
+async function pullExternalSpec(externalLocation, localPath, isPrivate = false) {
   let retries = 0;
   // retry 3 times before giving up
   while (retries < 3) {
     try {
       fs.writeFileSync(
         localPath,
-        await fetch(externalLocation).then(response => {
+        await fetch(externalLocation, {
+          headers: {
+            "PRIVATE-TOKEN": isPrivate ? PRIVATE_TOKEN : ''
+          }
+        }).then(response => {
           if (!response.ok) {
             throw new Error(`HTTP error! Status: ${response.status}`);
           }
@@ -113,6 +118,7 @@ async function run() {
     const specMachineName = currentSpecDefinition['name'];
     const specDisplayName = currentSpecDefinition['displayName'] || currentSpecDefinition['name'];
     const specLocation = currentSpecDefinition['location'];
+    const isSpecPrivate = currentSpecDefinition['isPrivate'];
     const potentialLocalSpecLocation = `${initialProjectDirectory}${path.sep}${specLocation}`;
     const outputSpecLocation = `${specMachineName}${path.sep}openapi.yaml`;
 
@@ -122,7 +128,7 @@ async function run() {
     console.log(`Retrieving openapi spec for ${specDisplayName}...`);
     // prepare the spec, fetching remote specs or copying the spec for processing
     if (isExternalSpec(specLocation)) {
-      await pullExternalSpec(specLocation, outputSpecLocation);
+      await pullExternalSpec(specLocation, outputSpecLocation, isSpecPrivate);
     } else {
       fs.copyFileSync(potentialLocalSpecLocation, outputSpecLocation);
       console.log(`Copied local spec for ${specDisplayName} to output dir`);
-- 
GitLab


From 6c3b50278507b66b63bd67b2c3463227457fea38 Mon Sep 17 00:00:00 2001
From: Martin Lowe <martin.lowe@eclipse-foundation.org>
Date: Fri, 30 May 2025 09:16:37 -0400
Subject: [PATCH 2/3] fix: add missing param in documentation

---
 src/index.js | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/index.js b/src/index.js
index 435bd79..c38f7d6 100644
--- a/src/index.js
+++ b/src/index.js
@@ -31,6 +31,7 @@ const PRIVATE_TOKEN = process.env.GITLAB_API_TOKEN;
  *
  * @param {*} externalLocation the URL for the raw openapi spec file.
  * @param {*} localPath the location where the downloaded spec should be saved
+ * @param {boolean} isPrivate optional, whether an external spec is in a private GitLab repository and should use secret token for access
  */
 async function pullExternalSpec(externalLocation, localPath, isPrivate = false) {
   let retries = 0;
-- 
GitLab


From 9d196b892bb3f1e732d241e81256367410c13902 Mon Sep 17 00:00:00 2001
From: Martin Lowe <martin.lowe@eclipse-foundation.org>
Date: Fri, 8 Aug 2025 15:11:55 -0400
Subject: [PATCH 3/3] feat: Update Jenkinsfile to use the Jenkins gitliab token
 for access

---
 Jenkinsfile | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Jenkinsfile b/Jenkinsfile
index 3930b1c..3e74782 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -1,5 +1,9 @@
 @Library('releng-pipeline') _
 
+withCredentials([string(credentialsId: 'gitlab-api-token', variable: 'GITLAB_API_TOKEN')]) {
+    env.GITLAB_API_TOKEN = GITLAB_API_TOKEN
+}
+
 hugo (
   appName: 'webdev.eclipse.org-spec-host',
   productionDomain: 'webdev.eclipse.org',
-- 
GitLab