-
Notifications
You must be signed in to change notification settings - Fork 371
fix: suppress GitHub REST API deprecation warnings by adding X-GitHub-Api-Version header #29743
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,14 @@ const { createRateLimitAwareGithub } = require("./github_rate_limit_logger.cjs") | |
| */ | ||
| function setupGlobals(coreModule, githubModule, contextModule, execModule, ioModule, getOctokitFn) { | ||
| global.core = coreModule; | ||
| // Inject X-GitHub-Api-Version header on every request to suppress the | ||
| // "@octokit/request: endpoint is deprecated" warning that fires when the | ||
| // unversioned GitHub REST API is used. | ||
| githubModule.hook.before("request", options => { | ||
| if (!options.headers["X-GitHub-Api-Version"]) { | ||
|
Contributor
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. Me see header check. Good guard! No overwrite caller header. Smart caveman move. 🦴 |
||
| options.headers["X-GitHub-Api-Version"] = "2022-11-28"; | ||
| } | ||
| }); | ||
| // @ts-expect-error - Assigning to global properties that are declared as const | ||
| // Wrap the github object so every github.rest.*.*() call automatically logs | ||
| // x-ratelimit-* headers to github_rate_limits.jsonl for observability. | ||
|
|
@@ -35,7 +43,17 @@ function setupGlobals(coreModule, githubModule, contextModule, execModule, ioMod | |
| global.exec = execModule; | ||
| // @ts-expect-error - Assigning to global properties that are declared as const | ||
| global.io = ioModule; | ||
| global.getOctokit = getOctokitFn; | ||
| // Wrap getOctokit so every client created via global.getOctokit(token) also | ||
| // carries X-GitHub-Api-Version, suppressing the deprecation warning for | ||
| // per-handler authenticated clients (cross-repo PAT operations, etc.). | ||
| global.getOctokit = (token, options = {}) => | ||
| getOctokitFn(token, { | ||
| ...options, | ||
|
Contributor
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. Consider extracting |
||
| headers: { | ||
|
Contributor
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. Me like wrap! All token clients get header too. No miss. Centralized fix good. 🪨 |
||
| "X-GitHub-Api-Version": "2022-11-28", | ||
| ...(options.headers || {}), | ||
|
Comment on lines
+52
to
+54
|
||
| }, | ||
|
Comment on lines
+52
to
+55
|
||
| }); | ||
| } | ||
|
|
||
| module.exports = { setupGlobals }; | ||
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.
✅ Good approach using
hook.beforeto centrally inject theX-GitHub-Api-Versionheader. This ensures all requests through the globalgithubobject are covered without modifying individual call sites.