Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bin/doc-tools-mcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* - Telemetry: Usage tracking for adoption metrics
*/

// Load environment variables from .env file if it exists
require('dotenv').config();

const fs = require('fs');
const path = require('path');
const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
Expand Down
3 changes: 3 additions & 0 deletions bin/doc-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

'use strict'

// Load environment variables from .env file if it exists
require('dotenv').config()

const { spawnSync } = require('child_process')
const os = require('os')
const { Command, Option } = require('commander')
Expand Down
36 changes: 36 additions & 0 deletions cli-utils/octokit-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict'

const { Octokit } = require('@octokit/rest')
const { getGitHubToken } = require('./github-token')

/**
* Shared Octokit client instance for GitHub API access
* Configured with optional authentication and retry logic
*
* This singleton instance is shared across all doc-tools modules to:
* - Avoid redundant initialization
* - Share rate limit tracking
* - Centralize GitHub API configuration
*/

// Get authentication token from environment
const token = getGitHubToken()

// Configure Octokit options
const octokitOptions = {
userAgent: 'redpanda-docs-tools',
retry: {
enabled: true,
retries: 3
}
}

// Only add auth if token is available
if (token) {
octokitOptions.auth = token
}

// Create singleton instance
const octokit = new Octokit(octokitOptions)

module.exports = octokit
8 changes: 3 additions & 5 deletions extensions/generate-rp-connect-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ module.exports.register = function ({ config }) {
// Use csvpath (legacy) or csvPath
const localCsvPath = csvpath || null

async function loadOctokit () {
const { Octokit } = await import('@octokit/rest')
const { getGitHubToken } = require('../cli-utils/github-token')
const token = getGitHubToken()
return token ? new Octokit({ auth: token }) : new Octokit()
function loadOctokit () {
// Use shared Octokit client
return require('../cli-utils/octokit-client')
}

// Use 'on' and return the promise so Antora waits for async completion
Expand Down
23 changes: 18 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@redpanda-data/docs-extensions-and-macros",
"version": "4.13.4",
"version": "4.13.5",
"description": "Antora extensions and macros developed for Redpanda documentation.",
"keywords": [
"antora",
Expand Down Expand Up @@ -103,6 +103,7 @@
"chalk": "4.1.2",
"cheerio": "^1.1.2",
"commander": "^14.0.0",
"dotenv": "^16.6.1",
"glob": "^11.0.0",
"gulp": "^4.0.2",
"gulp-connect": "^5.7.0",
Expand Down
4 changes: 2 additions & 2 deletions tools/cloud-regions/generate-cloud-regions.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ function displayClusterType(ct) {
*/
async function fetchYaml({ owner, repo, path, ref = 'main', token }) {
try {
const { Octokit } = await import('@octokit/rest');
const octokit = new Octokit(token ? { auth: token } : {});
// Use shared Octokit client
const octokit = require('../../cli-utils/octokit-client');

console.log(`[cloud-regions] INFO: Fetching ${owner}/${repo}/${path}@${ref} via GitHub API`);

Expand Down
21 changes: 4 additions & 17 deletions tools/fetch-from-github.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
const fs = require('fs');
const path = require('path');

let octokitInstance = null;
async function loadOctokit() {
if (!octokitInstance) {
const { Octokit } = await import('@octokit/rest');
octokitInstance = process.env.VBOT_GITHUB_API_TOKEN
? new Octokit({
auth: process.env.VBOT_GITHUB_API_TOKEN,
})
: new Octokit();

if (!process.env.VBOT_GITHUB_API_TOKEN) {
console.info(
'No GitHub token found (VBOT_GITHUB_API_TOKEN).'
);
}
}
return octokitInstance;
// Use shared Octokit client
function loadOctokit() {
const octokit = require('../cli-utils/octokit-client');
return octokit;
}

async function saveFile(content, saveDir, filename) {
Expand Down
9 changes: 2 additions & 7 deletions tools/get-console-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,8 @@ module.exports = async function getConsoleVersion({ beta = false, fromAntora = f
useBeta = getPrereleaseFromAntora();
}

// Initialize GitHub client
const { getGitHubToken } = require('../cli-utils/github-token');
const { Octokit } = await import('@octokit/rest');
const token = getGitHubToken();
const octokit = token
? new Octokit({ auth: token })
: new Octokit();
// Use shared Octokit client
const octokit = require('../cli-utils/octokit-client');

// Fetch latest release info
let data;
Expand Down
9 changes: 2 additions & 7 deletions tools/get-redpanda-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ module.exports = async function getRedpandaVersion({ beta = false, fromAntora =
useBeta = getPrereleaseFromAntora();
}

// Load Octokit
const { getGitHubToken } = require('../cli-utils/github-token');
const { Octokit } = await import('@octokit/rest');
const token = getGitHubToken();
const octokit = token
? new Octokit({ auth: token })
: new Octokit();
// Use shared Octokit client
const octokit = require('../cli-utils/octokit-client');

// Fetch version data
let data;
Expand Down
12 changes: 1 addition & 11 deletions tools/redpanda-connect/connector-binary-analyzer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Octokit } = require('@octokit/rest');
const octokit = require('../../cli-utils/octokit-client');
const { execSync, spawnSync } = require('child_process');
const fs = require('fs');
const path = require('path');
Expand All @@ -13,16 +13,6 @@ const https = require('https');
* - Which connectors are self-hosted only
*/

// Initialize Octokit with optional authentication
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
userAgent: 'redpanda-docs-tools',
retry: {
enabled: true,
retries: 3
}
});

const REPO_OWNER = 'redpanda-data';
const REPO_NAME = 'connect';

Expand Down
11 changes: 8 additions & 3 deletions tools/redpanda-connect/helpers/buildConfigYaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ module.exports = function buildConfigYaml(type, connectorName, children, include
return; // skip deprecated fields
}
if (!includeAdvanced && field.is_advanced) {
return; // skip advanced fields in common mode
return; // skip advanced fields in "common" mode
}

if (field.type === 'object' && Array.isArray(field.children)) {
// Render nested object
// Check if this is an array-of-objects (e.g., client_certs[])
// These should render as empty arrays, not expanded object structures
if (field.kind === 'array' && field.type === 'object' && Array.isArray(field.children)) {
// Render as array leaf (e.g., "client_certs: []")
lines.push(renderLeafField(field, baseIndent));
} else if (field.type === 'object' && Array.isArray(field.children)) {
// Render nested object (plain object, not array)
const nestedLines = renderObjectField(field, baseIndent);
lines.push(...nestedLines);
} else {
Expand Down
7 changes: 6 additions & 1 deletion tools/redpanda-connect/helpers/renderObjectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ module.exports = function renderObjectField(field, indentLevel) {
if (child.is_deprecated) {
return; // skip entirely
}
if (Array.isArray(child.children) && child.children.length > 0) {
// Check if this is an array-of-objects (e.g., client_certs[])
// These should render as empty arrays, not expanded object structures
if (child.kind === 'array' && child.type === 'object' && Array.isArray(child.children)) {
// Render as array leaf (e.g., "client_certs: []")
lines.push(renderLeafField(child, childIndent));
} else if (Array.isArray(child.children) && child.children.length > 0) {
// Nested object → recurse
lines.push(...renderObjectField(child, childIndent));
} else {
Expand Down
Loading