diff --git a/src/data_providers/issuable.ts b/src/data_providers/issuable.ts index a8d31eb92faa9159adb5d4d727ca892d50d0145e..6f5a138f25130795094a696553d0fea9d64255d8 100644 --- a/src/data_providers/issuable.ts +++ b/src/data_providers/issuable.ts @@ -29,6 +29,7 @@ export class DataProvider implements vscode.TreeDataProvider export class GitLabNewService { client: GraphQLClient; - instanceUrl: string; - - constructor(instanceUrl: string) { - this.instanceUrl = instanceUrl; + constructor(readonly instanceUrl: string, readonly pipelineInstanceUrl?: string) { const endpoint = new URL('/api/graphql', this.instanceUrl).href; this.client = new GraphQLClient(endpoint, this.fetchOptions); } diff --git a/src/service_factory.ts b/src/service_factory.ts index b2896c83dcac426acb01597d2bc020791dc4d95f..dacb28aef355d1921f99eea12b1b23d137570329 100644 --- a/src/service_factory.ts +++ b/src/service_factory.ts @@ -1,18 +1,16 @@ -import * as vscode from 'vscode'; import * as assert from 'assert'; import { GitService } from './git_service'; import { GitLabNewService } from './gitlab/gitlab_new_service'; import { getInstanceUrl } from './utils/get_instance_url'; +import { getExtensionConfiguration } from './utils/get_extension_configuration'; export function createGitService(workspaceFolder: string): GitService { assert(workspaceFolder, 'git service requires workspaceFolder to function'); - const { remoteName, pipelineGitRemoteName } = vscode.workspace.getConfiguration('gitlab'); - // the getConfiguration() returns null for missing attributes, we need to convert them to - // undefined so that we can use optional properties and default function parameters + const { remoteName, pipelineGitRemoteName } = getExtensionConfiguration(); return new GitService({ workspaceFolder, - remoteName: remoteName || undefined, - pipelineGitRemoteName: pipelineGitRemoteName || undefined, + remoteName, + pipelineGitRemoteName, }); } diff --git a/src/status_bar.js b/src/status_bar.js index 5f03fb2575e9f1b0ab7dfdb1091ef00f9f6d7a29..50897c03f7072b927baa5afa1fc35a458927cddf 100644 --- a/src/status_bar.js +++ b/src/status_bar.js @@ -8,6 +8,7 @@ const { USER_COMMANDS } = require('./command_names'); const MAXIMUM_DISPLAYED_JOBS = 4; +// FIXME: if you are touching this configuration statement, move the configuration to get_extension_configuration.ts const { showStatusBarLinks, showIssueLinkOnStatusBar, diff --git a/src/token_service_wrapper.js b/src/token_service_wrapper.js index 556495a2f1c2c80cc57698134103c1ecad922d73..95d7b2d4ca779f569671eaab5cb1c09bc12cbe81 100644 --- a/src/token_service_wrapper.js +++ b/src/token_service_wrapper.js @@ -8,6 +8,7 @@ const { USER_COMMANDS } = require('./command_names'); let context = null; let active = false; +// FIXME: if you are touching this configuration statement, move the configuration to get_extension_configuration.ts const currentInstanceUrl = () => vscode.workspace.getConfiguration('gitlab').instanceUrl || GITLAB_COM_URL; diff --git a/src/utils/get_extension_configuration.ts b/src/utils/get_extension_configuration.ts new file mode 100644 index 0000000000000000000000000000000000000000..32f26bbcea271cc4e845035cdf55b5c0263ff13e --- /dev/null +++ b/src/utils/get_extension_configuration.ts @@ -0,0 +1,18 @@ +import * as vscode from 'vscode'; +import { CONFIG_NAMESPACE } from '../constants'; + +interface ExtensionConfiguration { + remoteName?: string; + pipelineGitRemoteName?: string; +} + +// VS Code returns a value or `null` but undefined is better for using default function arguments +const turnNullToUndefined = (val: T | null | undefined): T | undefined => val ?? undefined; + +export function getExtensionConfiguration(): ExtensionConfiguration { + const workspaceConfig = vscode.workspace.getConfiguration(CONFIG_NAMESPACE); + return { + remoteName: turnNullToUndefined(workspaceConfig.remoteName), + pipelineGitRemoteName: turnNullToUndefined(workspaceConfig.pipelineGitRemoteName), + }; +} diff --git a/src/utils/get_http_agent_options.ts b/src/utils/get_http_agent_options.ts index a360ef57407e7ef2ad62968876d8fad7e03e57dd..731fbb1dd3e4e26c2864c67395d664f16817fb41 100644 --- a/src/utils/get_http_agent_options.ts +++ b/src/utils/get_http_agent_options.ts @@ -13,6 +13,7 @@ interface GitLabHttpAgentOptions { export const getHttpAgentOptions = (): GitLabHttpAgentOptions => { const result: GitLabHttpAgentOptions = {}; + // FIXME: if you are touching this configuration statement, move the configuration to get_extension_configuration.ts const { ignoreCertificateErrors, ca, cert, certKey } = vscode.workspace.getConfiguration( 'gitlab', ); @@ -40,6 +41,7 @@ export const getHttpAgentOptions = (): GitLabHttpAgentOptions => { } } + // FIXME: if you are touching this configuration statement, move the configuration to get_extension_configuration.ts const { proxy } = vscode.workspace.getConfiguration('http'); result.proxy = proxy || undefined; return result; diff --git a/src/utils/get_instance_url.ts b/src/utils/get_instance_url.ts index d58df99bc94c5364f1c03572e42e8fd9096e6219..fa8035262c3e37bddb81160d41385ed29332f56e 100644 --- a/src/utils/get_instance_url.ts +++ b/src/utils/get_instance_url.ts @@ -68,6 +68,7 @@ async function heuristicInstanceUrl(workspaceFolder: string) { } export async function getInstanceUrl(workspaceFolder?: string): Promise { + // FIXME: if you are touching this configuration statement, move the configuration to get_extension_configuration.ts const { instanceUrl } = vscode.workspace.getConfiguration('gitlab'); // if the workspace setting exists, use it if (instanceUrl) { diff --git a/test/integration/tree_view.test.js b/test/integration/tree_view.test.js index 81ce455b44a7a4897f36b81e5c2c6115990b902b..8c78ef203b7a41be577359cc1f52a09a0a2984f8 100644 --- a/test/integration/tree_view.test.js +++ b/test/integration/tree_view.test.js @@ -100,6 +100,7 @@ describe('GitLab tree view', () => { }), ]); await tokenService.setToken(GITLAB_URL, 'abcd-secret'); + // FIXME: if you are touching this configuration statement, move the configuration to get_extension_configuration.ts await vscode.workspace.getConfiguration().update('gitlab.customQueries', customQuerySettings); }); @@ -111,6 +112,7 @@ describe('GitLab tree view', () => { after(async () => { server.close(); await tokenService.setToken(GITLAB_URL, undefined); + // FIXME: if you are touching this configuration statement, move the configuration to get_extension_configuration.ts await vscode.workspace.getConfiguration().update('gitlab.customQueries', undefined); });