@redpanda-data/docs-extensions-and-macros 5.3.7 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,19 +5,68 @@
5
5
  * Supports multiple common token variable names with priority order.
6
6
  */
7
7
 
8
+ /**
9
+ * Extract a GitHub token from the GIT_CREDENTIALS environment variable.
10
+ *
11
+ * GIT_CREDENTIALS is the variable Antora's own credential manager reads, so in
12
+ * Antora builds (for example, Netlify) it is the source guaranteed to hold a
13
+ * working credential for private content sources. Entries follow the git
14
+ * credential store format and may be separated by commas or newlines:
15
+ *
16
+ * https://<token>:@github.com
17
+ * https://<username>:<password>@github.com
18
+ * https://x-access-token:<token>@github.com
19
+ *
20
+ * @param {string} [credentials] - Credential contents (defaults to process.env.GIT_CREDENTIALS)
21
+ * @returns {string|null} GitHub token or null if no github.com entry found
22
+ */
23
+ function getTokenFromGitCredentials(credentials = process.env.GIT_CREDENTIALS) {
24
+ if (!credentials) return null;
25
+
26
+ for (const entry of credentials.split(/[,\n]/)) {
27
+ const match = entry.trim().match(/^https?:\/\/([^@]+)@([^/]+)/);
28
+ // Exact host match (optional port) so entries for lookalike hosts such as
29
+ // github.com.evil.example or notgithub.com are never treated as GitHub.
30
+ if (!match || !/^github\.com(:\d+)?$/i.test(match[2])) continue;
31
+
32
+ const [username, ...passwordParts] = match[1].split(':');
33
+ const password = passwordParts.join(':');
34
+
35
+ // Token may sit in the username position (https://TOKEN:@github.com) or,
36
+ // when a username such as x-access-token is present, in the password position.
37
+ const token = password || username;
38
+ if (!token) continue;
39
+
40
+ try {
41
+ return decodeURIComponent(token);
42
+ } catch (err) {
43
+ return token;
44
+ }
45
+ }
46
+
47
+ return null;
48
+ }
49
+
8
50
  /**
9
51
  * Get GitHub token from environment variables
10
52
  * Checks multiple common variable names in priority order:
11
- * 1. REDPANDA_GITHUB_TOKEN - Custom Redpanda token
12
- * 2. ACTIONS_BOT_TOKEN - GitHub Actions bot token
13
- * 3. GITHUB_TOKEN - GitHub Actions default
14
- * 4. VBOT_GITHUB_API_TOKEN - Legacy bot token
15
- * 5. GH_TOKEN - GitHub CLI default
53
+ * 1. GIT_CREDENTIALS - Antora's credential store contents (github.com entry)
54
+ * 2. REDPANDA_GITHUB_TOKEN - Custom Redpanda token
55
+ * 3. ACTIONS_BOT_TOKEN - GitHub Actions bot token
56
+ * 4. GITHUB_TOKEN - GitHub Actions default
57
+ * 5. VBOT_GITHUB_API_TOKEN - Legacy bot token
58
+ * 6. GH_TOKEN - GitHub CLI default
59
+ *
60
+ * Note: this resolver feeds both git clone/fetch auth and GitHub API clients
61
+ * (Octokit). Wherever GIT_CREDENTIALS is set (for example, Antora builds on
62
+ * Netlify), API calls authenticate with that same token, whose API scopes may
63
+ * differ from the token env vars it outranks.
16
64
  *
17
65
  * @returns {string|null} GitHub token or null if not found
18
66
  */
19
67
  function getGitHubToken() {
20
- return process.env.REDPANDA_GITHUB_TOKEN ||
68
+ return getTokenFromGitCredentials() ||
69
+ process.env.REDPANDA_GITHUB_TOKEN ||
21
70
  process.env.ACTIONS_BOT_TOKEN ||
22
71
  process.env.GITHUB_TOKEN ||
23
72
  process.env.VBOT_GITHUB_API_TOKEN ||
@@ -57,6 +106,7 @@ function hasGitHubToken() {
57
106
 
58
107
  module.exports = {
59
108
  getGitHubToken,
109
+ getTokenFromGitCredentials,
60
110
  getAuthenticatedGitHubUrl,
61
111
  hasGitHubToken
62
112
  };
@@ -3,6 +3,7 @@
3
3
  const { execSync } = require('child_process')
4
4
  const fs = require('fs')
5
5
  const path = require('path')
6
+ const { getGitHubToken } = require('../cli-utils/github-token')
6
7
 
7
8
  /**
8
9
  * Configure Antora to use full git clones instead of shallow clones.
@@ -66,6 +67,30 @@ module.exports.register = function ({ config, playbook }) {
66
67
  let unshallowedCount = 0
67
68
  const unshallowTimeout = config?.unshallowTimeout || 60000 // Default 60 seconds per repo
68
69
 
70
+ // Private repos need credentials: the git CLI does not share Antora's
71
+ // built-in credential manager, so resolve a token (GIT_CREDENTIALS first,
72
+ // then the common token env vars) and hand it to git through a credential
73
+ // helper. Both the config and the token travel via environment variables
74
+ // (GIT_CONFIG_* and GIT_FULL_CLONE_TOKEN), so nothing touches the command
75
+ // line, the remote URL, or the cached .git/config, and there is no shell
76
+ // quoting to break on other platforms. Config entry 0 clears any inherited
77
+ // helpers; entry 1 registers a helper scoped to github.com so no other
78
+ // host is ever offered the token.
79
+ const token = getGitHubToken()
80
+ const gitCommand = 'git fetch --unshallow'
81
+ const gitEnv = { ...process.env, GIT_TERMINAL_PROMPT: '0' }
82
+ if (token) {
83
+ logger.info(' → Using GitHub token for unshallow fetches')
84
+ gitEnv.GIT_FULL_CLONE_TOKEN = token
85
+ gitEnv.GIT_CONFIG_COUNT = '2'
86
+ gitEnv.GIT_CONFIG_KEY_0 = 'credential.helper'
87
+ gitEnv.GIT_CONFIG_VALUE_0 = ''
88
+ gitEnv.GIT_CONFIG_KEY_1 = 'credential.https://github.com.helper'
89
+ gitEnv.GIT_CONFIG_VALUE_1 = '!f() { echo "username=x-access-token"; echo "password=$GIT_FULL_CLONE_TOKEN"; }; f'
90
+ } else {
91
+ logger.info(' → No GitHub token found; unshallow may fail for private repos')
92
+ }
93
+
69
94
  for (const aggregate of contentAggregate) {
70
95
  for (const origin of aggregate.origins || []) {
71
96
  const gitdir = origin.gitdir
@@ -80,11 +105,11 @@ module.exports.register = function ({ config, playbook }) {
80
105
  logger.info(` → Unshallowing ${path.basename(gitdir)}...`)
81
106
 
82
107
  // Use git fetch --unshallow to convert to full clone
83
- execSync('git fetch --unshallow', {
108
+ execSync(gitCommand, {
84
109
  cwd: gitdir,
85
110
  stdio: 'pipe',
86
111
  timeout: unshallowTimeout,
87
- env: { ...process.env, GIT_TERMINAL_PROMPT: '0' }
112
+ env: gitEnv
88
113
  })
89
114
 
90
115
  const duration = Date.now() - startTime
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redpanda-data/docs-extensions-and-macros",
3
- "version": "5.3.7",
3
+ "version": "5.7.0",
4
4
  "description": "Antora extensions and macros developed for Redpanda documentation.",
5
5
  "keywords": [
6
6
  "antora",