deepsource-mcp-server
Version:
Model Context Protocol server for DeepSource
129 lines (128 loc) • 5.02 kB
TypeScript
/**
* @fileoverview QualityMetrics repository implementation
*
* Concrete implementation of IQualityMetricsRepository using DeepSource API.
*/
import { IQualityMetricsRepository } from '../../domain/aggregates/quality-metrics/quality-metrics.repository.js';
import { QualityMetrics } from '../../domain/aggregates/quality-metrics/quality-metrics.aggregate.js';
import { ProjectKey } from '../../types/branded.js';
import { MetricShortcode, MetricKey } from '../../models/metrics.js';
import { QualityMetricsId } from '../../domain/aggregates/quality-metrics/quality-metrics.types.js';
import { DeepSourceClient } from '../../deepsource.js';
/**
* Concrete implementation of IQualityMetricsRepository using DeepSource API
*
* This repository provides access to QualityMetrics aggregates by fetching data
* from the DeepSource API and mapping it to domain models.
*
* Note: The DeepSource API returns metrics at the repository level with items
* for each context (language). This repository maps each item to a separate
* QualityMetrics aggregate. This ensures fresh data retrieval on every request
* as per requirements.
*/
export declare class QualityMetricsRepository implements IQualityMetricsRepository {
private readonly client;
constructor(client: DeepSourceClient);
/**
* Helper method to get repository ID for a project
*
* @param projectKey - The project key
* @returns The repository GraphQL ID
*/
private getRepositoryId;
/**
* Finds metrics by composite ID
*
* @param id - The composite ID (projectKey:metricKey:shortcode)
* @returns The metrics if found, null otherwise
*/
findById(id: string): Promise<QualityMetrics | null>;
/**
* Finds all metrics for a project
*
* @param projectKey - The project key
* @returns All quality metrics for the project
*/
findByProject(projectKey: ProjectKey): Promise<QualityMetrics[]>;
/**
* Finds metrics for a project with server-side filtering
*
* @param projectKey - The project key
* @param shortcodeIn - Array of metric shortcodes to filter by
* @returns Filtered quality metrics for the project
*/
findByProjectWithFilter(projectKey: ProjectKey, shortcodeIn: MetricShortcode[]): Promise<QualityMetrics[]>;
/**
* Finds metrics by project and metric type
*
* @param projectKey - The project key
* @param shortcode - The metric shortcode
* @param metricKey - Optional metric key filter
* @returns The metrics if found, null otherwise
*/
findByProjectAndMetric(projectKey: ProjectKey, shortcode: MetricShortcode, metricKey?: MetricKey): Promise<QualityMetrics | null>;
/**
* Finds all metrics with failing thresholds for a project
*
* @param projectKey - The project key
* @returns Metrics that are currently failing their thresholds
*/
findFailingMetrics(projectKey: ProjectKey): Promise<QualityMetrics[]>;
/**
* Finds all reported metrics for a project
*
* @param projectKey - The project key
* @returns Metrics that have isReported set to true
*/
findReportedMetrics(projectKey: ProjectKey): Promise<QualityMetrics[]>;
/**
* Finds metrics by composite ID components
*
* @param id - The composite ID components
* @returns The metrics if found, null otherwise
*/
findByCompositeId(id: QualityMetricsId): Promise<QualityMetrics | null>;
/**
* Counts total metrics for a project
*
* @param projectKey - The project key
* @returns The total number of metrics
*/
countByProject(projectKey: ProjectKey): Promise<number>;
/**
* Counts failing metrics for a project
*
* @param projectKey - The project key
* @returns The number of failing metrics
*/
countFailingByProject(projectKey: ProjectKey): Promise<number>;
/**
* Checks if metrics exist for a project and shortcode
*
* @param projectKey - The project key
* @param shortcode - The metric shortcode
* @returns True if metrics exist, false otherwise
*/
exists(projectKey: ProjectKey, shortcode: MetricShortcode): Promise<boolean>;
/**
* Saves quality metrics
*
* Note: The DeepSource API only supports updating thresholds and settings,
* not creating new metrics. This method updates the threshold if needed.
*
* @param metrics - The metrics to save
* @throws Error if the metric doesn't exist or update fails
*/
save(metrics: QualityMetrics): Promise<void>;
/**
* Deletes quality metrics
*
* Note: The DeepSource API doesn't support deleting metrics.
* This method is implemented to satisfy the interface but will
* throw an error indicating the operation is not supported.
*
* @param id - The metrics ID to delete
* @throws Error indicating the operation is not supported
*/
delete(id: string): Promise<void>;
}