Skip to content

Commit d6ed4aa

Browse files
committed
Use gh CLI for token when available
1 parent f32c8b2 commit d6ed4aa

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

scripts/postinstall.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,24 @@ function getVersion() {
4141
}
4242

4343
function getGitHubToken() {
44-
// Check environment variables (in order of preference)
45-
return (
46-
process.env.GITHUB_TOKEN ||
47-
process.env.GH_TOKEN ||
48-
process.env.GITHUB_PAT ||
49-
null
50-
);
44+
// Check environment variables first
45+
if (process.env.GITHUB_TOKEN) return process.env.GITHUB_TOKEN;
46+
if (process.env.GH_TOKEN) return process.env.GH_TOKEN;
47+
48+
// Try gh CLI (GitHub's official CLI)
49+
try {
50+
const token = execSync("gh auth token", {
51+
encoding: "utf8",
52+
stdio: ["pipe", "pipe", "pipe"],
53+
}).trim();
54+
if (token && token.startsWith("gh")) {
55+
return token;
56+
}
57+
} catch {
58+
// gh CLI not installed or not logged in
59+
}
60+
61+
return null;
5162
}
5263

5364
function httpsGet(url, token = null) {

0 commit comments

Comments
 (0)