Skip to content

Commit

Permalink
fix: display base branch only for Code in issue tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Catalina Oyaneder committed Jul 15, 2024
1 parent f757c5c commit 4307560
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/snyk/common/constants/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const SNYK_CONTEXT = {
ERROR: 'error',
MODE: 'mode',
ADVANCED: 'advanced',
DELTA_FINDINGS_ENABLED: 'deltaFindingsEnabled',
};

export const SNYK_ERROR_CODES = {
Expand Down
8 changes: 7 additions & 1 deletion src/snyk/common/services/productService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IConfiguration } from '../configuration/configuration';
import { IWorkspaceTrust } from '../configuration/trustedFolders';
import { CodeActionsProvider } from '../editor/codeActionsProvider';
import { ILanguageServer } from '../languageServer/languageServer';
import { Issue, Scan, ScanStatus } from '../languageServer/types';
import { Issue, Scan, ScanProduct, ScanStatus } from '../languageServer/types';
import { ILog } from '../logger/interfaces';
import { IViewManagerService } from '../services/viewManagerService';
import { IProductWebviewProvider } from '../views/webviewProvider';
Expand All @@ -29,6 +29,8 @@ export interface IProductService<T> extends AnalysisStatusProvider, Disposable {
}

export abstract class ProductService<T> extends AnalysisStatusProvider implements IProductService<T> {
abstract readonly productType: ScanProduct;

private _result: ProductResult<T>;
readonly newResultAvailable$ = new Subject<void>();

Expand Down Expand Up @@ -59,6 +61,10 @@ export abstract class ProductService<T> extends AnalysisStatusProvider implement

abstract refreshTreeView(): void;

public getSnykProductType(): ScanProduct {
return this.productType;
}

registerCodeActionsProvider(provider: CodeActionsProvider<T>) {
this.languages.registerCodeActionsProvider({ scheme: 'file', language: '*' }, provider);
}
Expand Down
11 changes: 8 additions & 3 deletions src/snyk/common/views/issueTreeProvider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import _, { flatten } from 'lodash';
import * as vscode from 'vscode'; // todo: invert dependency
import { IConfiguration, IssueViewOptions } from '../../common/configuration/configuration';
import { Issue, IssueSeverity } from '../../common/languageServer/types';
import { Issue, IssueSeverity, ScanProduct } from '../../common/languageServer/types';
import { messages as commonMessages } from '../../common/messages/analysisMessages';
import { IContextService } from '../../common/services/contextService';
import { IProductService } from '../../common/services/productService';
import { IProductService, ProductService } from '../../common/services/productService';
import { AnalysisTreeNodeProvider } from '../../common/views/analysisTreeNodeProvider';
import { INodeIcon, InternalType, NODE_ICONS, TreeNode } from '../../common/views/treeNode';
import { IVSCodeLanguages } from '../../common/vscode/languages';
Expand Down Expand Up @@ -91,12 +91,17 @@ export abstract class ProductIssueTreeProvider<T> extends AnalysisTreeNodeProvid
const ignoredIssueCount = this.getIgnoredCount();

const topNodes: (TreeNode | null)[] = [
this.getBaseBranch(),
new TreeNode({
text: this.getIssueFoundText(totalIssueCount, ignoredIssueCount),
}),
this.getFixableIssuesNode(this.getFixableCount()),
];

const isSnykCodeProduct = (this.productService as ProductService<T>).getSnykProductType() === ScanProduct.Code;
if (isSnykCodeProduct) {
topNodes.unshift(this.getBaseBranch());
}

const noSeverityFiltersSelectedWarning = this.getNoSeverityFiltersSelectedTreeNode();
if (noSeverityFiltersSelectedWarning !== null) {
topNodes.push(noSeverityFiltersSelectedWarning);
Expand Down
2 changes: 2 additions & 0 deletions src/snyk/snykCode/codeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { SnykCodeActionsProvider } from './codeActions/codeIssuesActionsProvider
import { ICodeSuggestionWebviewProvider } from './views/interfaces';

export class SnykCodeService extends ProductService<CodeIssueData> {
public readonly productType = ScanProduct.Code;

constructor(
extensionContext: ExtensionContext,
config: IConfiguration,
Expand Down
2 changes: 2 additions & 0 deletions src/snyk/snykIac/iacService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { IacCodeActionsProvider } from './codeActions/iacCodeActionsProvider';
import { IIacSuggestionWebviewProvider } from './views/interfaces';

export class IacService extends ProductService<IacIssueData> {
public readonly productType = ScanProduct.InfrastructureAsCode;

constructor(
extensionContext: ExtensionContext,
config: IConfiguration,
Expand Down
2 changes: 2 additions & 0 deletions src/snyk/snykOss/ossService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { IOssSuggestionWebviewProvider } from './interfaces';
import { OssCodeActionsProvider } from './providers/ossCodeActionsProvider';

export class OssService extends ProductService<OssIssueData> {
public readonly productType = ScanProduct.OpenSource;

constructor(
extensionContext: ExtensionContext,
config: IConfiguration,
Expand Down
2 changes: 2 additions & 0 deletions src/test/unit/common/services/productService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type ProductData = {
productName: string;
};
class MockProductService extends ProductService<ProductData> {
productType: ScanProduct;

subscribeToLsScanMessages(): Subscription {
return this.languageServer.scan$.subscribe((scan: Scan<unknown>) => {
super.handleLsScanMessage(scan as Scan<ProductData>);
Expand Down

0 comments on commit 4307560

Please sign in to comment.