Loading src/gitlab/gitlab_service.ts +2 −2 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ import { createDiffNoteMutation, GqlDiffPositionInput } from './graphql/create_d import { removeLeadingSlash } from '../utils/remove_leading_slash'; import { logError } from '../log'; import { isMr } from '../utils/is_mr'; import { ifVersionGte } from './if_version_gte'; import { ifVersionGte } from '../utils/if_version_gte'; import { getSnippetContentQuery, GetSnippetContentQueryOptions, Loading Loading @@ -488,7 +488,7 @@ export class GitLabService { assert(result?.project?.mergeRequest, `MR ${mr.references.full} was not found.`); return Boolean(result.project.mergeRequest.userPermissions?.createNote); }, () => false, async () => false, ); } Loading src/openers.ts +12 −3 Original line number Diff line number Diff line Loading @@ -8,9 +8,18 @@ import { } from './commands/run_with_valid_project'; import { gitExtensionWrapper } from './git/git_extension_wrapper'; import { GitLabRepository } from './git/wrapped_repository'; export const openUrl = async (url: string): Promise<void> => vscode.commands.executeCommand(VS_COMMANDS.OPEN, vscode.Uri.parse(url)); import { ifVersionGte } from './utils/if_version_gte'; export const openUrl = async (url: string): Promise<void> => { // workaround for a VS Code open command bug: https://gitlab.com/gitlab-org/gitlab-vscode-extension/-/issues/44 const urlArgument = ifVersionGte<string | vscode.Uri>( vscode.version, '1.65.0', () => url, () => vscode.Uri.parse(url), ); await vscode.commands.executeCommand(VS_COMMANDS.OPEN, urlArgument); }; /** * Fetches user and project before opening a link. Loading src/gitlab/if_version_gte.test.ts→src/utils/if_version_gte.test.ts +0 −0 File moved. View file src/gitlab/if_version_gte.ts→src/utils/if_version_gte.ts +18 −5 Original line number Diff line number Diff line Loading @@ -2,23 +2,36 @@ import assert from 'assert'; import { coerce, gte, valid } from 'semver'; import { log, LOG_LEVEL } from '../log'; /** * This method runs different code for different versions (VS Code, GitLab API, ...). * * - If the method can't parse the `current` version, it will execute the **then** part. * - If the method can't parse the `minimumRequiredVersion`, it will throw an assertion error. * * @param current the version this extension uses * @param minimumRequiredVersion the version where `then` code block can execute safely * @param then code to be executed on the the minimumRequiredVersion or higher * @param otherwise code to be executed on lower versions * @returns */ export function ifVersionGte<T>( current: string | undefined, minimumRequiredVersion: string, then: () => T | Promise<T>, otherwise: () => T | Promise<T>, ): T | Promise<T> { then: () => T, otherwise: () => T, ): T { assert( valid(minimumRequiredVersion), `minimumRequiredVersion argument ${minimumRequiredVersion} isn't valid`, ); if (!coerce(current)) { const parsedCurrent = coerce(current); if (!parsedCurrent) { log( `Could not parse version from "${current}", running logic for the latest GitLab version`, LOG_LEVEL.WARNING, ); return then(); } if (gte(coerce(current)!, minimumRequiredVersion)) return then(); if (gte(parsedCurrent, minimumRequiredVersion)) return then(); return otherwise(); } test/integration/create_snippet.test.js +1 −1 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ describe('Create snippet', async () => { .mock(vscode.commands) .expects('executeCommand') .once() .withArgs('vscode.open', vscode.Uri.parse(snippetUrl)); .withArgs('vscode.open', snippetUrl); await originalExecuteCommand(USER_COMMANDS.CREATE_SNIPPET); expectation.verify(); Loading Loading
src/gitlab/gitlab_service.ts +2 −2 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ import { createDiffNoteMutation, GqlDiffPositionInput } from './graphql/create_d import { removeLeadingSlash } from '../utils/remove_leading_slash'; import { logError } from '../log'; import { isMr } from '../utils/is_mr'; import { ifVersionGte } from './if_version_gte'; import { ifVersionGte } from '../utils/if_version_gte'; import { getSnippetContentQuery, GetSnippetContentQueryOptions, Loading Loading @@ -488,7 +488,7 @@ export class GitLabService { assert(result?.project?.mergeRequest, `MR ${mr.references.full} was not found.`); return Boolean(result.project.mergeRequest.userPermissions?.createNote); }, () => false, async () => false, ); } Loading
src/openers.ts +12 −3 Original line number Diff line number Diff line Loading @@ -8,9 +8,18 @@ import { } from './commands/run_with_valid_project'; import { gitExtensionWrapper } from './git/git_extension_wrapper'; import { GitLabRepository } from './git/wrapped_repository'; export const openUrl = async (url: string): Promise<void> => vscode.commands.executeCommand(VS_COMMANDS.OPEN, vscode.Uri.parse(url)); import { ifVersionGte } from './utils/if_version_gte'; export const openUrl = async (url: string): Promise<void> => { // workaround for a VS Code open command bug: https://gitlab.com/gitlab-org/gitlab-vscode-extension/-/issues/44 const urlArgument = ifVersionGte<string | vscode.Uri>( vscode.version, '1.65.0', () => url, () => vscode.Uri.parse(url), ); await vscode.commands.executeCommand(VS_COMMANDS.OPEN, urlArgument); }; /** * Fetches user and project before opening a link. Loading
src/gitlab/if_version_gte.ts→src/utils/if_version_gte.ts +18 −5 Original line number Diff line number Diff line Loading @@ -2,23 +2,36 @@ import assert from 'assert'; import { coerce, gte, valid } from 'semver'; import { log, LOG_LEVEL } from '../log'; /** * This method runs different code for different versions (VS Code, GitLab API, ...). * * - If the method can't parse the `current` version, it will execute the **then** part. * - If the method can't parse the `minimumRequiredVersion`, it will throw an assertion error. * * @param current the version this extension uses * @param minimumRequiredVersion the version where `then` code block can execute safely * @param then code to be executed on the the minimumRequiredVersion or higher * @param otherwise code to be executed on lower versions * @returns */ export function ifVersionGte<T>( current: string | undefined, minimumRequiredVersion: string, then: () => T | Promise<T>, otherwise: () => T | Promise<T>, ): T | Promise<T> { then: () => T, otherwise: () => T, ): T { assert( valid(minimumRequiredVersion), `minimumRequiredVersion argument ${minimumRequiredVersion} isn't valid`, ); if (!coerce(current)) { const parsedCurrent = coerce(current); if (!parsedCurrent) { log( `Could not parse version from "${current}", running logic for the latest GitLab version`, LOG_LEVEL.WARNING, ); return then(); } if (gte(coerce(current)!, minimumRequiredVersion)) return then(); if (gte(parsedCurrent, minimumRequiredVersion)) return then(); return otherwise(); }
test/integration/create_snippet.test.js +1 −1 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ describe('Create snippet', async () => { .mock(vscode.commands) .expects('executeCommand') .once() .withArgs('vscode.open', vscode.Uri.parse(snippetUrl)); .withArgs('vscode.open', snippetUrl); await originalExecuteCommand(USER_COMMANDS.CREATE_SNIPPET); expectation.verify(); Loading