提交 db1f479e 编写于 作者: T Tomas Vik

Merge branch '359-warn-users-that-they-should-use-supported-gitlab-version' into 'main'

fix: minimum version check

See merge request gitlab-org/gitlab-vscode-extension!286
......@@ -7,4 +7,5 @@ export const DELETED = 'deleted';
export const RENAMED = 'renamed';
export const MODIFIED = 'modified';
export const DO_NOT_SHOW_VERSION_WARNING = 'DO_NOT_SHOW_VERSION_WARNING';
export const MINIMUM_VERSION = 13.5;
// NOTE: This needs to _always_ be a 3 digits
export const MINIMUM_VERSION = '13.5.0';
......@@ -48,6 +48,7 @@ describe('check_version', () => {
${'13.5.0'}
${'13.6.3'}
${'13.6.0-pre'}
${'13.6.0-pre-1'}
${'13.12.4'}
${'abc13.5def'}
`('gets $version successfully', async ({ version }) => {
......@@ -57,7 +58,7 @@ describe('check_version', () => {
expect(vscode.window.showErrorMessage).not.toHaveBeenCalled();
});
xit(`shows warning when version is below 13.5`, async () => {
it(`shows warning when version is below 13.5`, async () => {
mockedRepositories = [createMockRepo(`13.4.2`)];
await getVersionForEachRepo(gitExtensionWrapper, context as vscode.ExtensionContext);
......@@ -72,7 +73,7 @@ describe('check_version', () => {
expect(logMock.log).toHaveBeenCalledWith(`Could not match version from "${BAD_VERSION}"`);
});
xit('stores user preference for not showing the warning', async () => {
it('stores user preference for not showing the warning', async () => {
mockedRepositories = [createMockRepo('13.4')];
(vscode.window.showErrorMessage as jest.Mock).mockResolvedValue('Do not show again');
......
......@@ -8,31 +8,37 @@ export const getVersionForEachRepo = async (
context: vscode.ExtensionContext,
): Promise<void> => {
const DO_NOT_SHOW_AGAIN_TEXT = 'Do not show again';
const toSegments = (version?: string) => {
const match = version?.match(/\d+/g) || [];
return match.map(Number);
};
const minimumSegments = toSegments(MINIMUM_VERSION);
await Promise.all(
gitExtensionWrapper.repositories.map(async repo => {
const version = await repo.getVersion();
const versionMatch = version?.match(/\d+\.\d+/);
if (!versionMatch) {
log(`Could not match version from "${version}"`);
const repoVersion = await repo.getVersion();
const versionSegments = toSegments(repoVersion);
if (!versionSegments.length) {
log(`Could not match version from "${repoVersion}"`);
return;
}
const versionNumber = versionMatch[0];
const parsedVersionNumber = parseFloat(versionNumber);
const minimumVersionCheckPassed = minimumSegments.every(
(n, i) => n <= (versionSegments[i] ?? 0),
);
if (parsedVersionNumber >= MINIMUM_VERSION) return;
if (minimumVersionCheckPassed) return;
const warningMessage = `This extension requires GitLab version ${MINIMUM_VERSION} or later. Repo "${repo.name}" is currently using ${version}.`;
const warningMessage = `This extension requires GitLab version ${MINIMUM_VERSION} or later. Repo "${repo.name}" is currently using ${repoVersion}.`;
log(warningMessage);
// if (!context.workspaceState.get(DO_NOT_SHOW_VERSION_WARNING)) {
// const action = await vscode.window.showErrorMessage(warningMessage, DO_NOT_SHOW_AGAIN_TEXT);
if (!context.workspaceState.get(DO_NOT_SHOW_VERSION_WARNING)) {
const action = await vscode.window.showErrorMessage(warningMessage, DO_NOT_SHOW_AGAIN_TEXT);
// if (action === DO_NOT_SHOW_AGAIN_TEXT)
// await context.workspaceState.update(DO_NOT_SHOW_VERSION_WARNING, true);
// }
if (action === DO_NOT_SHOW_AGAIN_TEXT)
await context.workspaceState.update(DO_NOT_SHOW_VERSION_WARNING, true);
}
}),
).catch(error => log(error));
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册