|
1 | 1 | import * as vscode from "vscode"; |
| 2 | +import {deactivateLanguageServer, initLanguageServer} from "../workflow/languageServer"; |
| 3 | +import {resetGitHubContext} from "../git/repository"; |
2 | 4 |
|
3 | 5 | const settingsKey = "github-actions"; |
| 6 | +const DEFAULT_GITHUB_API = "https://api.github.com"; |
4 | 7 |
|
5 | 8 | export function initConfiguration(context: vscode.ExtensionContext) { |
6 | 9 | context.subscriptions.push( |
7 | | - vscode.workspace.onDidChangeConfiguration(e => { |
| 10 | + vscode.workspace.onDidChangeConfiguration(async e => { |
8 | 11 | if (e.affectsConfiguration(getSettingsKey("workflows.pinned"))) { |
9 | 12 | pinnedWorkflowsChangeHandlers.forEach(h => h()); |
| 13 | + } else if ( |
| 14 | + e.affectsConfiguration(getSettingsKey("use-enterprise")) || |
| 15 | + (useEnterprise() && |
| 16 | + (e.affectsConfiguration("github-enterprise.uri") || e.affectsConfiguration(getSettingsKey("remote-name")))) |
| 17 | + ) { |
| 18 | + await updateLanguageServerApiUrl(context); |
| 19 | + resetGitHubContext(); |
| 20 | + await vscode.commands.executeCommand("github-actions.explorer.refresh"); |
10 | 21 | } |
11 | 22 | }) |
12 | 23 | ); |
@@ -52,3 +63,19 @@ export function pinnedWorkflowsRefreshInterval(): number { |
52 | 63 | export function getRemoteName(): string { |
53 | 64 | return getConfiguration().get<string>(getSettingsKey("remote-name"), "origin"); |
54 | 65 | } |
| 66 | + |
| 67 | +export function useEnterprise(): boolean { |
| 68 | + return getConfiguration().get<boolean>(getSettingsKey("use-enterprise"), false); |
| 69 | +} |
| 70 | + |
| 71 | +export function getGitHubApiUri(): string { |
| 72 | + if (!useEnterprise()) return DEFAULT_GITHUB_API; |
| 73 | + const base = getConfiguration().get<string>("github-enterprise.uri", DEFAULT_GITHUB_API).replace(/\/$/, ""); |
| 74 | + return base === DEFAULT_GITHUB_API ? base : `${base}/api/v3`; |
| 75 | +} |
| 76 | + |
| 77 | +async function updateLanguageServerApiUrl(context: vscode.ExtensionContext) { |
| 78 | + await deactivateLanguageServer(); |
| 79 | + |
| 80 | + await initLanguageServer(context); |
| 81 | +} |
0 commit comments