@graphteon/juricode
Version:
We are forging the future with lines of digital steel
177 lines • 6.99 kB
JavaScript
import prompts from 'prompts';
import chalk from 'chalk';
import ora from 'ora';
import boxen from 'boxen';
import { GitService } from '../api/git';
export const showUserInfo = async () => {
const spinner = ora('Fetching user info...').start();
try {
const gitService = new GitService();
const user = await gitService.getGitUser();
spinner.succeed('User info fetched successfully!');
console.log(boxen(`ID: ${chalk.cyan(user.id)}
Login: ${chalk.white(user.login)}
Name: ${chalk.white(user.name || 'N/A')}
Email: ${chalk.white(user.email || 'N/A')}
Company: ${chalk.white(user.company || 'N/A')}`, { padding: 1, borderColor: 'green' }));
}
catch (error) {
spinner.fail('Failed to fetch user info');
console.error(chalk.red(error instanceof Error ? error.message : 'Unknown error'));
}
};
export const searchRepositories = async () => {
const answer = await prompts([
{
type: 'text',
name: 'query',
message: 'Enter search query:',
validate: (input) => input.length > 0 || 'Search query is required'
},
{
type: 'number',
name: 'limit',
message: 'Enter number of results:',
initial: 5
}
]);
const spinner = ora('Searching repositories...').start();
try {
const gitService = new GitService();
const repos = await gitService.searchRepositories(answer.query, answer.limit);
spinner.succeed('Repositories found!');
if (repos.length === 0) {
console.log(chalk.yellow('No repositories found'));
return;
}
repos.forEach(repo => {
console.log(boxen(`Name: ${chalk.cyan(repo.full_name)}
Description: ${chalk.white(repo.description || 'N/A')}
Visibility: ${repo.private ? chalk.red('Private') : chalk.green('Public')}
Default Branch: ${chalk.yellow(repo.default_branch)}
URL: ${chalk.blue(repo.html_url)}`, {
padding: 1,
margin: { bottom: 1 },
borderColor: 'blue'
}));
});
}
catch (error) {
spinner.fail('Failed to search repositories');
console.error(chalk.red(error instanceof Error ? error.message : 'Unknown error'));
}
};
export const listRepositories = async () => {
const spinner = ora('Fetching repositories...').start();
try {
const gitService = new GitService();
const repos = await gitService.getUserRepositories();
spinner.succeed('Repositories fetched successfully!');
if (repos.length === 0) {
console.log(chalk.yellow('No repositories found'));
return;
}
repos.forEach(repo => {
console.log(boxen(`Name: ${chalk.cyan(repo.full_name)}
Description: ${chalk.white(repo.description || 'N/A')}
Visibility: ${repo.private ? chalk.red('Private') : chalk.green('Public')}
Default Branch: ${chalk.yellow(repo.default_branch)}
URL: ${chalk.blue(repo.html_url)}`, {
padding: 1,
margin: { bottom: 1 },
borderColor: 'blue'
}));
});
}
catch (error) {
spinner.fail('Failed to fetch repositories');
console.error(chalk.red(error instanceof Error ? error.message : 'Unknown error'));
}
};
export const listBranches = async () => {
const answer = await prompts({
type: 'text',
name: 'repository',
message: 'Enter repository (format: owner/repo):',
validate: (input) => input.length > 0 || 'Repository is required'
});
const spinner = ora('Fetching branches...').start();
try {
const gitService = new GitService();
const branches = await gitService.getRepositoryBranches(answer.repository);
spinner.succeed('Branches fetched successfully!');
if (branches.length === 0) {
console.log(chalk.yellow('No branches found'));
return;
}
branches.forEach(branch => {
console.log(boxen(`Name: ${chalk.cyan(branch.name)}
Protected: ${branch.protected ? chalk.red('Yes') : chalk.green('No')}`, {
padding: 1,
margin: { bottom: 1 },
borderColor: 'blue'
}));
});
}
catch (error) {
spinner.fail('Failed to fetch branches');
console.error(chalk.red(error instanceof Error ? error.message : 'Unknown error'));
}
};
export const viewGitChanges = async () => {
const answer = await prompts({
type: 'text',
name: 'conversationId',
message: 'Enter conversation ID:',
validate: (input) => input.length > 0 || 'Conversation ID is required'
});
const spinner = ora('Fetching git changes...').start();
try {
const gitService = new GitService();
const changes = await gitService.getGitChanges(answer.conversationId);
spinner.succeed('Git changes fetched successfully!');
if (changes.length === 0) {
console.log(chalk.yellow('No changes found'));
return;
}
console.log(boxen(chalk.white('Git Changes:') + '\n' + changes.map(change => `${change.status === 'modified' ? chalk.yellow('M') :
change.status === 'added' ? chalk.green('A') :
change.status === 'deleted' ? chalk.red('D') :
chalk.white('?')} ${change.path}`).join('\n'), { padding: 1, borderColor: 'yellow' }));
const diffAnswer = await prompts({
type: 'confirm',
name: 'viewDiff',
message: 'Would you like to view diff for a specific file?',
initial: false
});
if (diffAnswer.viewDiff) {
const fileAnswer = await prompts({
type: 'select',
name: 'file',
message: 'Select file to view diff:',
choices: changes.map(change => ({ title: change.path, value: change.path }))
});
const diffSpinner = ora('Fetching diff...').start();
try {
const diff = await gitService.getGitChangeDiff(answer.conversationId, fileAnswer.file);
diffSpinner.succeed('Diff fetched successfully!');
console.log(boxen(chalk.white(diff.diff), {
padding: 1,
margin: { top: 1 },
borderColor: 'cyan',
title: diff.path,
titleAlignment: 'center'
}));
}
catch (error) {
diffSpinner.fail('Failed to fetch diff');
console.error(chalk.red(error instanceof Error ? error.message : 'Unknown error'));
}
}
}
catch (error) {
spinner.fail('Failed to fetch git changes');
console.error(chalk.red(error instanceof Error ? error.message : 'Unknown error'));
}
};
//# sourceMappingURL=git.js.map