From 5aad51a917431ef471cf599784c68b787a654182 Mon Sep 17 00:00:00 2001 From: Alex Ross <38270282+alexr00@users.noreply.github.com> Date: Fri, 13 Feb 2026 10:47:54 +0100 Subject: [PATCH] Add environment variable support for automation --- src/github/credentials.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/github/credentials.ts b/src/github/credentials.ts index ce2f62b102..d4422d3607 100644 --- a/src/github/credentials.ts +++ b/src/github/credentials.ts @@ -130,6 +130,32 @@ export class CredentialStore extends Disposable { await this.context.globalState.update(LAST_USED_SCOPES_GITHUB_KEY, this._scopes); await this.context.globalState.update(LAST_USED_SCOPES_ENTERPRISE_KEY, this._scopesEnterprise); } + + private async tryInitializeFromEnvironmentToken(authProviderId: AuthProvider): Promise { + if (isEnterprise(authProviderId)) { + return undefined; + } + const token = process.env.GITHUB_OAUTH_TOKEN; + if (!token) { + return undefined; + } + Logger.debug('Attempting authentication using GITHUB_OAUTH_TOKEN environment variable.', CredentialStore.ID); + try { + const github = await this.createHub(token, authProviderId); + this._githubAPI = github; + this._sessionId = 'environment-token'; + if (!this._isInitialized) { + this._isInitialized = true; + this._onDidInitialize.fire(); + } + Logger.appendLine('Successfully authenticated using GITHUB_OAUTH_TOKEN environment variable.', CredentialStore.ID); + return { canceled: false }; + } catch (e) { + Logger.error(`Failed to authenticate using GITHUB_OAUTH_TOKEN: ${e.message}`, CredentialStore.ID); + return undefined; + } + } + private async initialize(authProviderId: AuthProvider, getAuthSessionOptions: vscode.AuthenticationGetSessionOptions = {}, scopes: string[] = (!isEnterprise(authProviderId) ? this._scopes : this._scopesEnterprise), requireScopes?: boolean): Promise { Logger.debug(`Initializing GitHub${getGitHubSuffix(authProviderId)} authentication provider.`, 'Authentication'); if (isEnterprise(authProviderId)) { @@ -139,6 +165,11 @@ export class CredentialStore extends Disposable { } } + const envResult = await this.tryInitializeFromEnvironmentToken(authProviderId); + if (envResult) { + return envResult; + } + if (getAuthSessionOptions.createIfNone === undefined && getAuthSessionOptions.forceNewSession === undefined) { getAuthSessionOptions.createIfNone = false; }