From 7c28a63812bc4de358596b35a615b1f077e4f607 Mon Sep 17 00:00:00 2001 From: Eric Schneider <37347760+eric-schneider@users.noreply.github.com> Date: Tue, 12 Mar 2024 18:20:35 -0700 Subject: [PATCH] Update project files --- .gitignore | 1 + lib/pull-request-draft.js | 63 --------------------------------------- 2 files changed, 1 insertion(+), 63 deletions(-) delete mode 100644 lib/pull-request-draft.js diff --git a/.gitignore b/.gitignore index f3dce9a4..6bada636 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ **/.idea **/*.iml *.http +**/.java-version #build **/package-lock.json diff --git a/lib/pull-request-draft.js b/lib/pull-request-draft.js deleted file mode 100644 index 141649c0..00000000 --- a/lib/pull-request-draft.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict' - -// This extension allows for overriding content source branches at build time -// -// CONTENT_SOURCES should be a JSON object in the format of -// { -// "content_source_url" : { "build_branch": "[name of branch to be overridden]", "draft_branch": "[name of branch to use instead]" } -// } -// -// ex: -// -// { "https://github.com/riptano/datastax-docs-site.git": { "build_branch": "main", "draft_branch": "pull-request-branch" } } -// -// Above will replace the content source with URL https://github.com/riptano/datastax-docs-site.git -// with the object contents provided. In this case replacing the "branches" attribute with the provided value. -// -// usage: -// -// CONTENT_SOURCES='{ "https://github.com/riptano/datastax-docs-site.git" : { "build_branch": "main", "draft_branch": "test-pr" } }' \ -// antora --stacktrace --fetch antora-playbooks/release.yaml --extension lib/pull-request-draft.js - -// Helper method for wrapping item into an array if not already an array -const arrayWrap = (obj) => ( - Array.isArray(obj) - ? obj - : (obj === null || obj === undefined) ? [] : [obj] - ); - -// Register the extension -module.exports.register = function () { - this.once('playbookBuilt', async ({ playbook }) => { - const logger = this.getLogger('pr-draft-extension') - - const providedContentSources = process.env.CONTENT_SOURCES; - - if (!providedContentSources || providedContentSources == "{}") { - logger.warn("No content source changes specified. Using content sources defined in playbook as-is."); - return; - } - - let contentSourceChanges; - - try { - contentSourceChanges = JSON.parse(providedContentSources); - } catch(e) { - logger.error('CONTENT_SOURCES error! ' + e); - return; - } - - // Replace each content source with its provided override, if any. - playbook.content.sources.map((source) => { - let override = contentSourceChanges[source.url]; - if (override) { - let branches = source.branches || arrayWrap(playbook.content.branches || 'main') - branches = branches.map(branch => branch == override.build_branch ? override.draft_branch : branch); - let sourceOverride = Object.assign(source, { branches: branches }); - return sourceOverride; - } else { - return source; - } - }); - }) -}