Skip to content

Commit 0e1368b

Browse files
authored
Refine GitHub token handling in data generation script: Updated generate-github-data.js to clarify token sourcing priorities and improve console messaging for token status, enhancing user guidance for API access management. (#1)
1 parent 4f9274c commit 0e1368b

1 file changed

Lines changed: 9 additions & 17 deletions

File tree

scripts/generate-github-data.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -205,25 +205,23 @@ async function main() {
205205

206206
// --- GitHub token for accessing private repos (optional) ---
207207
//
208-
// Sources (in order of preference):
209-
// 1. fileConfig.githubToken (explicit, user-controlled)
210-
// 2. process.env.GITHUB_TOKEN *only* when it looks like a personal token
211-
// (ghp_... or github_pat_...), NOT the Actions default ghs_ token
208+
// Priority:
209+
// 1. fileConfig.githubToken (explicit, user-controlled)
210+
// 2. process.env.GITHUB_TOKEN (built-in Actions token or a PAT)
211+
// 3. no token (public / unauthenticated requests)
212212
//
213-
// This avoids 401s when the default GitHub Actions GITHUB_TOKEN does not
214-
// have permission to call certain REST/GraphQL APIs, while still letting
215-
// users opt in by adding a real PAT as a secret.
213+
// NOTE: The default GitHub Actions GITHUB_TOKEN may not have permission
214+
// for all REST/GraphQL APIs. If it returns 401s, users should provide
215+
// a real personal access token (ghp_... / github_pat_...) via either
216+
// gitforge.config.json or a repository secret.
216217
const rawEnvToken = process.env.GITHUB_TOKEN && process.env.GITHUB_TOKEN.trim()
217-
const envLooksLikePat =
218-
!!rawEnvToken &&
219-
(rawEnvToken.startsWith('ghp_') || rawEnvToken.startsWith('github_pat_'))
220218

221219
const configToken =
222220
fileConfig.githubToken && typeof fileConfig.githubToken === 'string'
223221
? fileConfig.githubToken.trim()
224222
: null
225223

226-
const githubToken = configToken || (envLooksLikePat ? rawEnvToken : null)
224+
const githubToken = configToken || rawEnvToken || null
227225

228226
// Debug: Log token status (without exposing the actual token)
229227
if (githubToken) {
@@ -233,12 +231,6 @@ async function main() {
233231
console.log(
234232
`GitHub token found: ${githubToken.substring(0, 7)}... (from ${source})`,
235233
)
236-
} else if (rawEnvToken && !envLooksLikePat) {
237-
console.log(
238-
'Ignoring default GitHub Actions GITHUB_TOKEN for API auth; using unauthenticated requests instead. ' +
239-
'To enable private-repo stats and higher limits, add a personal access token (ghp_... or github_pat_...) ' +
240-
'as the GITHUB_TOKEN secret or set githubToken in gitforge.config.json.',
241-
)
242234
} else {
243235
console.log(
244236
'No GitHub token found. Using unauthenticated GitHub API requests. ' +

0 commit comments

Comments
 (0)