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

refactor: hide commenting ranges behind feature flag

上级 c34adb9c
...@@ -6,3 +6,6 @@ export const ADDED = 'added'; ...@@ -6,3 +6,6 @@ export const ADDED = 'added';
export const DELETED = 'deleted'; export const DELETED = 'deleted';
export const RENAMED = 'renamed'; export const RENAMED = 'renamed';
export const MODIFIED = 'modified'; export const MODIFIED = 'modified';
// feature flags
export const FF_COMMENTING_RANGES = 'commenting-ranges';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { mr, mrVersion } from '../test_utils/entities'; import { mr, mrVersion } from '../test_utils/entities';
import { CommentingRangeProvider } from './commenting_range_provider'; import { CommentingRangeProvider } from './commenting_range_provider';
import { toReviewUri } from './review_uri'; import { ReviewParams, toReviewUri } from './review_uri';
import { getExtensionConfiguration } from '../utils/get_extension_configuration';
import { FF_COMMENTING_RANGES } from '../constants';
jest.mock('../utils/get_extension_configuration');
describe('CommentingRangeProvider', () => { describe('CommentingRangeProvider', () => {
let commentingRangeProvider: CommentingRangeProvider; let commentingRangeProvider: CommentingRangeProvider;
const commonUriParams: ReviewParams = {
path: `/path`,
mrId: mr.id,
projectId: mr.project_id,
commit: mrVersion.base_commit_sha,
workspacePath: '/',
};
const oldFileUrl = toReviewUri({
...commonUriParams,
commit: mrVersion.base_commit_sha,
});
const newFileUri = toReviewUri({
...commonUriParams,
commit: mrVersion.head_commit_sha,
});
beforeEach(() => { beforeEach(() => {
(getExtensionConfiguration as jest.Mock).mockReturnValue({
featureFlags: [FF_COMMENTING_RANGES],
});
commentingRangeProvider = new CommentingRangeProvider(mr, mrVersion); commentingRangeProvider = new CommentingRangeProvider(mr, mrVersion);
}); });
...@@ -19,13 +43,7 @@ describe('CommentingRangeProvider', () => { ...@@ -19,13 +43,7 @@ describe('CommentingRangeProvider', () => {
it('returns full range (all lines in the document) for old file', () => { it('returns full range (all lines in the document) for old file', () => {
const testDocument = { const testDocument = {
uri: toReviewUri({ uri: oldFileUrl,
path: `/path`,
mrId: mr.id,
projectId: mr.project_id,
commit: mrVersion.base_commit_sha,
workspacePath: '/',
}),
lineCount: 200, lineCount: 200,
} as vscode.TextDocument; } as vscode.TextDocument;
expect(commentingRangeProvider.provideCommentingRanges(testDocument)).toEqual([ expect(commentingRangeProvider.provideCommentingRanges(testDocument)).toEqual([
...@@ -35,13 +53,17 @@ describe('CommentingRangeProvider', () => { ...@@ -35,13 +53,17 @@ describe('CommentingRangeProvider', () => {
it('returns empty array for new file', () => { it('returns empty array for new file', () => {
const testDocument = { const testDocument = {
uri: toReviewUri({ uri: newFileUri,
path: `/path`, } as vscode.TextDocument;
mrId: mr.id, expect(commentingRangeProvider.provideCommentingRanges(testDocument)).toEqual([]);
projectId: mr.project_id, });
commit: mrVersion.head_commit_sha,
workspacePath: '/', it('returns empty array with the feature flag off', () => {
}), (getExtensionConfiguration as jest.Mock).mockReturnValue({
featureFlags: undefined,
});
const testDocument = {
uri: oldFileUrl,
lineCount: 200, lineCount: 200,
} as vscode.TextDocument; } as vscode.TextDocument;
expect(commentingRangeProvider.provideCommentingRanges(testDocument)).toEqual([]); expect(commentingRangeProvider.provideCommentingRanges(testDocument)).toEqual([]);
......
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { REVIEW_URI_SCHEME } from '../constants'; import { FF_COMMENTING_RANGES, REVIEW_URI_SCHEME } from '../constants';
import { getExtensionConfiguration } from '../utils/get_extension_configuration';
import { fromReviewUri } from './review_uri'; import { fromReviewUri } from './review_uri';
export class CommentingRangeProvider implements vscode.CommentingRangeProvider { export class CommentingRangeProvider implements vscode.CommentingRangeProvider {
...@@ -13,6 +14,7 @@ export class CommentingRangeProvider implements vscode.CommentingRangeProvider { ...@@ -13,6 +14,7 @@ export class CommentingRangeProvider implements vscode.CommentingRangeProvider {
} }
provideCommentingRanges(document: vscode.TextDocument): vscode.Range[] { provideCommentingRanges(document: vscode.TextDocument): vscode.Range[] {
if (!getExtensionConfiguration().featureFlags?.includes(FF_COMMENTING_RANGES)) return [];
const { uri } = document; const { uri } = document;
if (uri.scheme !== REVIEW_URI_SCHEME) return []; if (uri.scheme !== REVIEW_URI_SCHEME) return [];
const params = fromReviewUri(uri); const params = fromReviewUri(uri);
......
...@@ -4,6 +4,7 @@ import { CONFIG_NAMESPACE } from '../constants'; ...@@ -4,6 +4,7 @@ import { CONFIG_NAMESPACE } from '../constants';
interface ExtensionConfiguration { interface ExtensionConfiguration {
remoteName?: string; remoteName?: string;
pipelineGitRemoteName?: string; pipelineGitRemoteName?: string;
featureFlags?: string[];
} }
// VS Code returns a value or `null` but undefined is better for using default function arguments // VS Code returns a value or `null` but undefined is better for using default function arguments
...@@ -14,5 +15,6 @@ export function getExtensionConfiguration(): ExtensionConfiguration { ...@@ -14,5 +15,6 @@ export function getExtensionConfiguration(): ExtensionConfiguration {
return { return {
remoteName: turnNullToUndefined(workspaceConfig.remoteName), remoteName: turnNullToUndefined(workspaceConfig.remoteName),
pipelineGitRemoteName: turnNullToUndefined(workspaceConfig.pipelineGitRemoteName), pipelineGitRemoteName: turnNullToUndefined(workspaceConfig.pipelineGitRemoteName),
featureFlags: turnNullToUndefined(workspaceConfig.featureFlags),
}; };
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册