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 | /** * Repository Command * Manage repositories for continuous monitoring */ const { Command } = require('commander') const chalk = require('chalk') const inquirer = require('inquirer') const ora = require('ora') const { table } = require('table') const APIClient = require('../services/api-client') const ConfigManager = require('../utils/config-manager') const repoCommand = new Command('repo') .description('Manage repositories for continuous monitoring') // List repositories repoCommand .command('list') .alias('ls') .description('List monitored repositories') .action(async () => { const config = ConfigManager.getConfig() if (!config.auth?.accessToken) { console.error(chalk.red('❌ Not authenticated. Run vaultace auth login first.')) process.exit(1) } const spinner = ora('Fetching repositories...').start() try { const apiClient = new APIClient(config) const repositories = await apiClient.getRepositories() spinner.stop() if (repositories.length === 0) { console.log(chalk.gray('No repositories configured')) console.log(chalk.gray('Use vaultace repo add <url> to add a repository')) return } // Create table const tableData = [ [chalk.bold('Name'), chalk.bold('Provider'), chalk.bold('Branch'), chalk.bold('Status'), chalk.bold('Last Scan')] ] repositories.forEach(repo => { const statusColor = repo.scan_enabled ? chalk.green : chalk.gray const lastScan = repo.last_scan_at ? new Date(repo.last_scan_at).toLocaleDateString() : 'Never' tableData.push([ repo.name, repo.provider, repo.branch || 'main', statusColor(repo.scan_enabled ? 'Active' : 'Inactive'), lastScan ]) }) console.log(table(tableData, { border: { topBody: '─', topJoin: '┬', topLeft: '┌', topRight: '┐', bottomBody: '─', bottomJoin: '┴', bottomLeft: '└', bottomRight: '┘', bodyLeft: '│', bodyRight: '│', bodyJoin: '│' } })) } catch (error) { spinner.fail(`Failed to fetch repositories: ${error.message}`) process.exit(1) } }) // Add repository repoCommand .command('add') .description('Add repository for monitoring') .argument('<url>', 'repository URL') .option('-n, --name <name>', 'repository display name') .option('-b, --branch <branch>', 'branch to monitor', 'main') .option('-p, --provider <provider>', 'provider (github|gitlab|bitbucket)', 'github') .action(async (url, options) => { const config = ConfigManager.getConfig() if (!config.auth?.accessToken) { console.error(chalk.red('❌ Not authenticated. Run vaultace auth login first.')) process.exit(1) } try { // Extract repository name from URL if not provided let repoName = options.name if (!repoName) { const urlParts = url.replace(/\.git$/, '').split('/') repoName = urlParts[urlParts.length - 1] } // Validate provider const validProviders = ['github', 'gitlab', 'bitbucket'] if (!validProviders.includes(options.provider.toLowerCase())) { console.error(chalk.red(`Invalid provider. Must be one of: ${validProviders.join(', ')}`)) process.exit(1) } const spinner = ora(`Adding repository ${repoName}...`).start() const apiClient = new APIClient(config) const repository = await apiClient.addRepository( repoName, url, options.provider.toLowerCase(), options.branch ) spinner.succeed(`Repository ${repoName} added successfully!`) console.log(chalk.green('\n✅ Repository configured')) console.log(`${chalk.bold('Name:')} ${repository.name}`) console.log(`${chalk.bold('URL:')} ${repository.url}`) console.log(`${chalk.bold('Provider:')} ${repository.provider}`) console.log(`${chalk.bold('Branch:')} ${repository.branch}`) console.log(chalk.blue('\n🔍 Next steps:')) console.log('• Repository will be scanned automatically') console.log('• View results at: https://app.vaultace.com') console.log('• Run local scans with: vaultace scan --remote') } catch (error) { console.error(chalk.red(`Failed to add repository: ${error.message}`)) if (error.message.includes('already exists')) { console.log(chalk.gray('Use vaultace repo list to see existing repositories')) } process.exit(1) } }) // Remove repository repoCommand .command('remove') .alias('rm') .description('Remove repository from monitoring') .argument('<name-or-id>', 'repository name or ID') .option('-f, --force', 'skip confirmation prompt') .action(async (nameOrId, options) => { const config = ConfigManager.getConfig() if (!config.auth?.accessToken) { console.error(chalk.red('❌ Not authenticated. Run vaultace auth login first.')) process.exit(1) } try { const apiClient = new APIClient(config) // Get repositories to find the one to remove const repositories = await apiClient.getRepositories() const repository = repositories.find(r => r.name === nameOrId || r.id === nameOrId ) if (!repository) { console.error(chalk.red(`Repository not found: ${nameOrId}`)) console.log(chalk.gray('Use vaultace repo list to see available repositories')) process.exit(1) } // Confirmation if (!options.force) { const { confirm } = await inquirer.prompt([{ type: 'confirm', name: 'confirm', message: `Remove repository "${repository.name}"?`, default: false }]) if (!confirm) { console.log(chalk.gray('Operation cancelled')) return } } const spinner = ora(`Removing repository ${repository.name}...`).start() await apiClient.removeRepository(repository.id) spinner.succeed(`Repository ${repository.name} removed`) } catch (error) { console.error(chalk.red(`Failed to remove repository: ${error.message}`)) process.exit(1) } }) // Status subcommand repoCommand .command('status') .description('Show repository monitoring status') .action(async () => { const config = ConfigManager.getConfig() if (!config.auth?.accessToken) { console.error(chalk.red('❌ Not authenticated. Run vaultace auth login first.')) process.exit(1) } const spinner = ora('Checking repository status...').start() try { const apiClient = new APIClient(config) const repositories = await apiClient.getRepositories() spinner.stop() if (repositories.length === 0) { console.log(chalk.gray('No repositories configured')) return } console.log(chalk.bold(`\n📊 Repository Status (${repositories.length} total)\n`)) const activeRepos = repositories.filter(r => r.scan_enabled) const inactiveRepos = repositories.filter(r => !r.scan_enabled) console.log(`${chalk.green('✅ Active:')} ${activeRepos.length}`) console.log(`${chalk.gray('⭕ Inactive:')} ${inactiveRepos.length}`) // Recent scan activity const recentScans = repositories .filter(r => r.last_scan_at) .sort((a, b) => new Date(b.last_scan_at) - new Date(a.last_scan_at)) .slice(0, 3) if (recentScans.length > 0) { console.log(chalk.bold('\n🕒 Recent Activity:')) recentScans.forEach(repo => { const scanTime = new Date(repo.last_scan_at).toLocaleString() console.log(` ${repo.name} - ${scanTime}`) }) } console.log(chalk.blue('\n💡 Commands:')) console.log(' vaultace repo add <url> # Add repository') console.log(' vaultace scan --remote # Manual scan') console.log(' https://app.vaultace.com # View dashboard') } catch (error) { spinner.fail(`Failed to get repository status: ${error.message}`) process.exit(1) } }) module.exports = repoCommand |