Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | 3x 3x 3x 3x 3x 40x 40x 1x 39x 35x 35x 34x 1x 8x 1x 3x 31x 31x 38x 32x 32x 32x 32x 32x 4x 2x 2x 1x 1x 3x 2x 3x 3x 9x 3x 3x 3x 3x 9x 3x 3x 3x 2x 3x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 2x 2x 2x 3x 3x 2x 2x 3x 3x 2x 3x 1x 2x 1x 3x 3x 3x 3x 1x 2x 13x 13x 4x 39x 2x 37x 1x 36x 1x 35x 23x 23x 9x 9x 3x 1x 2x 1x 1x 3x | import { IProviderAdapter, ProviderConfig } from './IProviderAdapter.js'; import { GitLabAdapter } from './GitLabAdapter.js'; import { GitHubAdapter } from './GitHubAdapter.js'; import { AzureAdapter } from './AzureAdapter.js'; import { Provider } from '../types/index.js'; /** * Factory for creating provider adapters */ export class AdapterFactory { private constructor() { // Utility class - prevent instantiation } private static readonly adapterClasses = new Map<Provider, new () => IProviderAdapter>([ ['gitlab', GitLabAdapter], ['github', GitHubAdapter], ['azure', AzureAdapter], ]); /** * Create a new adapter instance for the specified provider */ static create(provider: Provider): IProviderAdapter { const AdapterClass = this.adapterClasses.get(provider); if (!AdapterClass) { throw new Error(`No adapter found for provider: ${provider}`); } return new AdapterClass(); } /** * Create and initialize an adapter */ static async createAndInitialize( provider: Provider, config: ProviderConfig, ): Promise<IProviderAdapter> { const adapter = this.create(provider); await adapter.initialize(config); return adapter; } /** * Get list of supported providers */ static getSupportedProviders(): Provider[] { return Array.from(this.adapterClasses.keys()); } /** * Check if a provider is supported */ static isSupported(provider: string): provider is Provider { return this.adapterClasses.has(provider as Provider); } /** * Register a custom adapter class */ static registerAdapter(provider: Provider, adapterClass: new () => IProviderAdapter): void { this.adapterClasses.set(provider, adapterClass); } } /** * Registry for managing active adapter instances */ export class AdapterRegistry { private adapters = new Map<string, IProviderAdapter>(); private configs = new Map<string, ProviderConfig>(); /** * Register an adapter instance with a unique key */ async register( key: string, provider: Provider, config: ProviderConfig, ): Promise<IProviderAdapter> { // Validate configuration this.validateConfig(provider, config); // Create and initialize adapter const adapter = await AdapterFactory.createAndInitialize(provider, config); // Store in registry this.adapters.set(key, adapter); this.configs.set(key, { ...config }); // Store copy console.log(`[AdapterRegistry] Registered ${provider} adapter with key: ${key}`); return adapter; } /** * Get adapter by key */ get(key: string): IProviderAdapter | undefined { return this.adapters.get(key); } /** * Get adapter by key, throw if not found */ getRequired(key: string): IProviderAdapter { const adapter = this.get(key); if (!adapter) { throw new Error(`Adapter not found: ${key}`); } return adapter; } /** * Get all registered adapter keys */ getKeys(): string[] { return Array.from(this.adapters.keys()); } /** * Get all adapters */ getAll(): Map<string, IProviderAdapter> { return new Map(this.adapters); } /** * Get adapters by provider type */ getByProvider(provider: Provider): Map<string, IProviderAdapter> { const result = new Map<string, IProviderAdapter>(); for (const [key, config] of this.configs.entries()) { if (this.detectProvider(config) === provider) { const adapter = this.adapters.get(key); Eif (adapter) { result.set(key, adapter); } } } return result; } /** * Check if adapter exists */ has(key: string): boolean { return this.adapters.has(key); } /** * Remove adapter from registry */ unregister(key: string): boolean { const removed = this.adapters.delete(key); this.configs.delete(key); if (removed) { console.log(`[AdapterRegistry] Unregistered adapter: ${key}`); } return removed; } /** * Clear all adapters */ clear(): void { this.adapters.clear(); this.configs.clear(); console.log(`[AdapterRegistry] Cleared all adapters`); } /** * Get adapter configuration */ getConfig(key: string): ProviderConfig | undefined { return this.configs.get(key); } /** * Update adapter configuration and reinitialize */ async updateConfig(key: string, newConfig: ProviderConfig): Promise<IProviderAdapter> { if (!this.has(key)) { throw new Error(`Adapter not found: ${key}`); } const provider = this.detectProvider(newConfig); this.validateConfig(provider, newConfig); // Create new adapter with updated config const adapter = await AdapterFactory.createAndInitialize(provider, newConfig); // Replace in registry this.adapters.set(key, adapter); this.configs.set(key, { ...newConfig }); console.log(`[AdapterRegistry] Updated configuration for: ${key}`); return adapter; } /** * Test connection for all registered adapters */ async testConnections(): Promise<Map<string, { success: boolean; error?: string }>> { const results = new Map<string, { success: boolean; error?: string }>(); for (const [key, adapter] of this.adapters.entries()) { try { const success = await adapter.validateConnection(); results.set(key, { success }); } catch (error) { results.set(key, { success: false, error: error instanceof Error ? error.message : String(error), }); } } return results; } /** * Get registry statistics */ getStats(): { totalAdapters: number; byProvider: Record<string, number>; activeConnections: number; } { const byProvider: Record<string, number> = {}; let activeConnections = 0; for (const config of this.configs.values()) { const provider = this.detectProvider(config); byProvider[provider] = (byProvider[provider] || 0) + 1; } // This is a simplification - in practice you'd want to actually test connections activeConnections = this.adapters.size; return { totalAdapters: this.adapters.size, byProvider, activeConnections, }; } /** * Create adapter key from config */ static createKey(provider: Provider, config: ProviderConfig): string { const parts: string[] = [provider]; if (config.organization) { parts.push(config.organization); } if (config.project) { parts.push(config.project); } else if (config.group) { parts.push(config.group); } return parts.join(':'); } /** * Parse adapter key back to components */ static parseKey(key: string): { provider: Provider; organization?: string; project?: string } { const parts = key.split(':'); const provider = parts[0] as Provider; if (!AdapterFactory.isSupported(provider)) { throw new Error(`Invalid provider in key: ${String(provider)}`); } return { provider, organization: parts[1], project: parts[2], }; } // Private helper methods private detectProvider(config: ProviderConfig): Provider { // Try to detect provider from config properties Eif (config.apiUrl) { if (config.apiUrl.includes('gitlab')) return 'gitlab'; Eif (config.apiUrl.includes('github')) return 'github'; if (config.apiUrl.includes('azure') || config.apiUrl.includes('dev.azure.com')) return 'azure'; } // Try to detect from config structure if (config.group) return 'gitlab' as Provider; // GitLab uses groups if (config.organization && config.apiUrl.includes('dev.azure.com')) return 'azure' as Provider; if (config.organization && !config.group) return 'github' as Provider; // GitHub uses orgs without groups throw new Error('Cannot detect provider type from configuration'); } private validateConfig(provider: Provider, config: ProviderConfig): void { // Common validations if (!config.id) { throw new Error('Configuration must have an id'); } if (!config.name) { throw new Error('Configuration must have a name'); } if (!config.token) { throw new Error('Configuration must have a token'); } // Provider-specific validations switch (provider) { case 'gitlab': Iif (!config.apiUrl) { throw new Error('GitLab configuration must have apiUrl'); } break; case 'github': Iif (!config.organization && !config.project?.includes('/')) { throw new Error( 'GitHub configuration must have organization or owner/repo format project', ); } break; case 'azure': if (!config.organization) { throw new Error('Azure DevOps configuration must have organization'); } if (!config.project) { throw new Error('Azure DevOps configuration must have project'); } break; } } } /** * Global adapter registry instance */ export const globalAdapterRegistry = new AdapterRegistry(); |