Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/patch-github-api-version-header.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion actions/setup/js/setup_globals.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Good approach using hook.before to centrally inject the X-GitHub-Api-Version header. This ensures all requests through the global github object are covered without modifying individual call sites.

githubModule.hook.before("request", options => {
if (!options.headers["X-GitHub-Api-Version"]) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.
Expand All @@ -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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting "2022-11-28" as a named constant (e.g. GITHUB_API_VERSION) so both call sites stay in sync if the version ever needs updating.

headers: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 };
Loading