-
Notifications
You must be signed in to change notification settings - Fork 823
Add GITHUB_API_BASE_URL environment variable #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1057,8 +1057,9 @@ IMPORTANT: | |
let treeData = null; | ||
let apiErrorDetails = ''; | ||
|
||
const apiBaseUrl = process.env.GITHUB_API_BASE_URL || 'https://api.github.com'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic for To make it more robust, what do you think about ensuring that Consider removing a potential trailing slash: const apiBaseUrl = (process.env.GITHUB_API_BASE_URL || 'https://api.github.com').replace(/\/$/, ''); |
||
for (const branch of ['main', 'master']) { | ||
const apiUrl = `https://api.github.com/repos/${owner}/${repo}/git/trees/${branch}?recursive=1`; | ||
const apiUrl = `${apiBaseUrl}/repos/${owner}/${repo}/git/trees/${branch}?recursive=1`; | ||
const headers = createGithubHeaders(token); | ||
|
||
console.log(`Fetching repository structure from branch: ${branch}`); | ||
|
@@ -1099,7 +1100,7 @@ IMPORTANT: | |
try { | ||
const headers = createGithubHeaders(token); | ||
|
||
const readmeResponse = await fetch(`https://api.github.com/repos/${owner}/${repo}/readme`, { | ||
const readmeResponse = await fetch(`${apiBaseUrl}/repos/${owner}/${repo}/readme`, { | ||
headers | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current construction of
api_url
has a couple of issues:GITHUB_API_BASE_URL
is not set,api_base_url
becomes"https://api.github.com"
. Then,api_url
becomesf"https://https://api.github.com/..."
, which is incorrect due to the doublehttps://
.GITHUB_API_BASE_URL
is set by the user and already includes thehttps://
scheme (e.g.,"https://my.ghe.com/api/v3"
), the same doublehttps://
issue will occur.GITHUB_API_BASE_URL
ends with a trailing slash (e.g.,"https://my.ghe.com/api/v3/"
), the resulting URL might have a double slash (e.g.,"...v3//repos/..."
), which is generally undesirable though often tolerated by servers.Could we adjust the logic to ensure the
GITHUB_API_BASE_URL
is expected to contain the scheme, and then we don't prependhttps://
? Also, stripping any trailing slash from the base URL would make it more robust. For example: