/**
* Base Provider Interface
*
* Abstract base class for VCS providers (GitHub, Gitea).
* Defines the common interface that all providers must implement.
*/
import { ProviderResult, ProviderOperation } from './types.js';
export abstract class BaseProvider {
protected name: string;
protected config: any;
constructor(name: string, config: any) {
this.name = name;
this.config = config;
}
/**
* Get the provider name
*/
getName(): string {
return this.name;
}
/**
* Check if the provider is properly configured
*/
abstract isConfigured(): boolean;
/**
* Validate provider credentials
*/
abstract validateCredentials(): Promise<boolean>;
/**
* Execute a provider operation
*/
abstract executeOperation(operation: string, params: any): Promise<ProviderResult>;
/**
* Get supported operations for this provider
*/
abstract getSupportedOperations(): string[];
/**
* Check if an operation is supported
*/
isOperationSupported(operation: string): boolean {
return this.getSupportedOperations().includes(operation);
}
/**
* Get provider configuration status
*/
getConfigurationStatus(): {
configured: boolean;
missingFields: string[];
provider: string;
} {
return {
configured: this.isConfigured(),
missingFields: this.getMissingConfigFields(),
provider: this.name
};
}
/**
* Get missing configuration fields
*/
protected abstract getMissingConfigFields(): string[];
/**
* Format error response
*/
protected formatError(code: string, message: string, details?: any): ProviderResult {
return {
success: false,
error: {
code,
message,
details
},
provider: this.name
};
}
/**
* Format success response
*/
protected formatSuccess(data?: any): ProviderResult {
return {
success: true,
data,
provider: this.name
};
}
}
/**
* Multi-provider interface for handling multiple providers simultaneously
*/
export interface MultiProvider {
providers: BaseProvider[];
executeOperation(operation: string, params: any): Promise<ProviderResult[]>;
getConfiguredProviders(): BaseProvider[];
isAnyProviderConfigured(): boolean;
}