UNPKG

forge-mutation-tester

Version:

Mutation testing tool for Solidity smart contracts using Gambit

63 lines 2.6 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GitService = void 0; const simple_git_1 = __importDefault(require("simple-git")); const fs_1 = require("fs"); const path_1 = __importDefault(require("path")); const chalk_1 = __importDefault(require("chalk")); const ora_1 = __importDefault(require("ora")); class GitService { git; constructor() { this.git = (0, simple_git_1.default)(); } async cloneRepository(repoUrl, targetDir, branch = 'main', token) { const spinner = (0, ora_1.default)('Cloning repository...').start(); try { // Parse the repository URL let cloneUrl = repoUrl; // If token is provided, inject it into the URL for private repos if (token) { const urlParts = new URL(repoUrl); urlParts.username = token; urlParts.password = 'x-oauth-basic'; cloneUrl = urlParts.toString(); } // Ensure target directory doesn't exist const repoName = path_1.default.basename(repoUrl, '.git'); const fullPath = path_1.default.join(targetDir, repoName); try { await fs_1.promises.access(fullPath); // Directory exists, remove it await fs_1.promises.rm(fullPath, { recursive: true, force: true }); } catch { // Directory doesn't exist, which is fine } // Clone the repository await this.git.clone(cloneUrl, fullPath, ['--branch', branch, '--depth', '1']); spinner.succeed(chalk_1.default.green(`Repository cloned successfully to ${fullPath}`)); return fullPath; } catch (error) { spinner.fail(chalk_1.default.red('Failed to clone repository')); throw error; } } async cleanup(repoPath) { const spinner = (0, ora_1.default)('Cleaning up cloned repository...').start(); try { await fs_1.promises.rm(repoPath, { recursive: true, force: true }); spinner.succeed(chalk_1.default.green('Cleanup completed')); } catch (error) { spinner.fail(chalk_1.default.yellow('Failed to cleanup repository')); // Don't throw, as cleanup failure is not critical } } } exports.GitService = GitService; //# sourceMappingURL=git.service.js.map