Skip to content

Commit 21d585f

Browse files
committed
Restore GitHub API user agent
1 parent 1545ac8 commit 21d585f

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/utils/documents.server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export function isRecoverableGitHubContentError(
7474
)
7575
}
7676

77+
const DEFAULT_GITHUB_API_USER_AGENT = 'TanStack-Docs'
78+
7779
export async function cancelUnusedResponseBody(
7880
response: Response,
7981
): Promise<void> {
@@ -880,9 +882,7 @@ function getGitHubContentFetchOptionsWithToken(
880882
headers['X-GitHub-Api-Version'] = '2022-11-28'
881883
}
882884

883-
if (opts?.userAgent) {
884-
headers['User-Agent'] = opts.userAgent
885-
}
885+
headers['User-Agent'] = opts?.userAgent ?? DEFAULT_GITHUB_API_USER_AGENT
886886

887887
if (token && opts?.includeAuthorization !== false) {
888888
headers.Authorization = `Bearer ${token}`

tests/github-content-fetch-options.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ assert.equal(
1616
'Bearer host-token',
1717
'GitHub API fetches use the Worker env token when present',
1818
)
19+
assert.equal(
20+
getHeaderValue(authenticatedOptions, 'User-Agent'),
21+
'TanStack-Docs',
22+
'GitHub API fetches include the required default User-Agent',
23+
)
1924

2025
const unauthenticatedOptions = runWithHostRuntimeEnv(
2126
{ GITHUB_AUTH_TOKEN: 'host-token' },
@@ -27,5 +32,13 @@ assert.equal(
2732
null,
2833
'GitHub API fetches can still opt out of authorization',
2934
)
35+
assert.equal(
36+
getHeaderValue(
37+
getGitHubContentFetchOptions({ userAgent: 'docs:tanstack/table' }),
38+
'User-Agent',
39+
),
40+
'docs:tanstack/table',
41+
'GitHub API fetches can override the default User-Agent',
42+
)
3043

3144
console.log('github-content-fetch-options tests passed')

0 commit comments

Comments
 (0)