Skip to content

Commit 37a92b2

Browse files
authored
fix: suppress GitHub REST API deprecation warnings by adding X-GitHub-Api-Version header (#29743)
1 parent 5289cc4 commit 37a92b2

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

.changeset/patch-github-api-version-header.md

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actions/setup/js/setup_globals.cjs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ const { createRateLimitAwareGithub } = require("./github_rate_limit_logger.cjs")
2626
*/
2727
function setupGlobals(coreModule, githubModule, contextModule, execModule, ioModule, getOctokitFn) {
2828
global.core = coreModule;
29+
// Inject X-GitHub-Api-Version header on every request to suppress the
30+
// "@octokit/request: endpoint is deprecated" warning that fires when the
31+
// unversioned GitHub REST API is used.
32+
githubModule.hook.before("request", options => {
33+
if (!options.headers["X-GitHub-Api-Version"]) {
34+
options.headers["X-GitHub-Api-Version"] = "2022-11-28";
35+
}
36+
});
2937
// @ts-expect-error - Assigning to global properties that are declared as const
3038
// Wrap the github object so every github.rest.*.*() call automatically logs
3139
// x-ratelimit-* headers to github_rate_limits.jsonl for observability.
@@ -35,7 +43,17 @@ function setupGlobals(coreModule, githubModule, contextModule, execModule, ioMod
3543
global.exec = execModule;
3644
// @ts-expect-error - Assigning to global properties that are declared as const
3745
global.io = ioModule;
38-
global.getOctokit = getOctokitFn;
46+
// Wrap getOctokit so every client created via global.getOctokit(token) also
47+
// carries X-GitHub-Api-Version, suppressing the deprecation warning for
48+
// per-handler authenticated clients (cross-repo PAT operations, etc.).
49+
global.getOctokit = (token, options = {}) =>
50+
getOctokitFn(token, {
51+
...options,
52+
headers: {
53+
"X-GitHub-Api-Version": "2022-11-28",
54+
...(options.headers || {}),
55+
},
56+
});
3957
}
4058

4159
module.exports = { setupGlobals };

0 commit comments

Comments
 (0)