@graphteon/juricode
Version:
We are forging the future with lines of digital steel
167 lines (166 loc) ⢠8.03 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.listRepositories = void 0;
const prompts_1 = __importDefault(require("prompts"));
const chalk_1 = __importDefault(require("chalk"));
const ora_1 = __importDefault(require("ora"));
const boxen_1 = __importDefault(require("boxen"));
const open_hands_1 = __importDefault(require("../api/open-hands"));
const chat_1 = require("./chat");
const listRepositories = async () => {
const spinner = (0, ora_1.default)('Fetching repositories...').start();
try {
const repos = await open_hands_1.default.retrieveUserGitRepositories();
spinner.succeed('Repositories fetched successfully!');
if (repos.length === 0) {
console.log(chalk_1.default.yellow('No repositories found'));
return;
}
let filteredRepos = repos;
if (repos.length > 10) {
const { useSearch } = await (0, prompts_1.default)({
type: 'confirm',
name: 'useSearch',
message: `Found ${repos.length} repositories. Would you like to search/filter them?`,
initial: false
});
if (useSearch) {
const { searchTerm } = await (0, prompts_1.default)({
type: 'text',
name: 'searchTerm',
message: 'Enter search term (repository name):',
validate: value => value.length > 0 ? true : 'Please enter a search term'
});
if (searchTerm) {
filteredRepos = repos.filter(repo => repo.full_name.toLowerCase().includes(searchTerm.toLowerCase()));
if (filteredRepos.length === 0) {
console.log(chalk_1.default.yellow(`No repositories found matching "${searchTerm}"`));
return await (0, exports.listRepositories)();
}
console.log(chalk_1.default.green(`Found ${filteredRepos.length} repositories matching "${searchTerm}"`));
}
}
}
const repositoryChoices = filteredRepos.map(repo => ({
title: `${chalk_1.default.blue(repo.full_name)} ${repo.stargazers_count && repo.stargazers_count > 0 ? chalk_1.default.yellow('ā
' + repo.stargazers_count) : ''}`,
value: repo,
description: `Provider: ${chalk_1.default.green(repo.git_provider)} | ${repo.is_public ? chalk_1.default.green('Public') : chalk_1.default.yellow('Private')}`
}));
const choices = [];
if (repos.length > 5) {
choices.push({
title: chalk_1.default.cyan('š Search repositories'),
value: 'search',
description: 'Filter repositories by name'
});
}
choices.push(...repositoryChoices);
const { selectedRepo } = await (0, prompts_1.default)({
type: 'select',
name: 'selectedRepo',
message: 'Select a repository:',
choices: choices
});
if (selectedRepo === 'search') {
return await (0, exports.listRepositories)();
}
if (!selectedRepo)
return;
console.log((0, boxen_1.default)(`Repository: ${chalk_1.default.blue(selectedRepo.full_name)}
Provider: ${chalk_1.default.green(selectedRepo.git_provider)}
Visibility: ${selectedRepo.is_public ? chalk_1.default.green('Public') : chalk_1.default.yellow('Private')}
Stars: ${chalk_1.default.yellow('ā
' + (selectedRepo.stargazers_count || 0))}`, {
padding: 1,
margin: { top: 1 },
borderColor: 'blue'
}));
const branchSpinner = (0, ora_1.default)('Fetching branches...').start();
let branches = [];
try {
branches = await open_hands_1.default.getRepositoryBranches(selectedRepo.full_name);
branchSpinner.succeed('Branches fetched successfully!');
}
catch (error) {
branchSpinner.fail('Failed to fetch branches');
console.error(chalk_1.default.red('Using default branch selection'));
}
let selectedBranch = 'main';
if (branches.length > 0) {
const defaultBranch = branches.find(b => b.name === 'main') ||
branches.find(b => b.name === 'master') ||
branches[0];
const { branch } = await (0, prompts_1.default)({
type: 'select',
name: 'branch',
message: 'Select a branch:',
choices: branches.map(branch => ({
title: `${chalk_1.default.cyan(branch.name)} ${branch.protected ? chalk_1.default.red('š') : ''}`,
value: branch.name,
description: branch.last_push_date ? `Last push: ${new Date(branch.last_push_date).toLocaleDateString()}` : ''
})),
initial: branches.findIndex(b => b.name === defaultBranch.name)
});
if (branch) {
selectedBranch = branch;
}
}
const { action } = await (0, prompts_1.default)({
type: 'select',
name: 'action',
message: 'What would you like to do with this repository?',
choices: [
{ title: 'š¬ Start Working on Repository', value: 'start-chat' },
{ title: 'ā©ļø Back to Repository List', value: 'back' },
{ title: 'š Return to Main Menu', value: 'main' }
]
});
if (action === 'start-chat') {
const { message } = await (0, prompts_1.default)({
type: 'text',
name: 'message',
message: 'Enter initial message (optional):'
});
const createSpinner = (0, ora_1.default)('Creating conversation...').start();
try {
const conversation = await open_hands_1.default.createConversation(selectedRepo.full_name, selectedRepo.git_provider, message || undefined, [], undefined, selectedBranch);
createSpinner.succeed('Conversation created successfully!');
console.log((0, boxen_1.default)(`š ${chalk_1.default.green('Repository Conversation Started!')}
Repository: ${chalk_1.default.blue(selectedRepo.full_name)}
Branch: ${chalk_1.default.cyan(selectedBranch)}
Conversation ID: ${chalk_1.default.cyan(conversation.conversation_id)}
Status: ${chalk_1.default.yellow(conversation.status)}`, {
padding: 1,
margin: { top: 1 },
borderColor: 'green',
borderStyle: 'double'
}));
const { startChat } = await (0, prompts_1.default)({
type: 'confirm',
name: 'startChat',
message: 'Would you like to start chatting with the AI about this repository?',
initial: true
});
if (startChat) {
console.log(chalk_1.default.blue('\nš¤ Starting chat session...\n'));
await (0, chat_1.runTaskChat)(conversation.conversation_id);
}
}
catch (error) {
createSpinner.fail('Failed to create conversation');
console.error(chalk_1.default.red(error instanceof Error ? error.message : 'Unknown error'));
}
}
else if (action === 'back') {
await (0, exports.listRepositories)();
}
}
catch (error) {
spinner.fail('Failed to fetch repositories');
console.error(chalk_1.default.red(error instanceof Error ? error.message : 'Unknown error'));
}
};
exports.listRepositories = listRepositories;
//# sourceMappingURL=repository.js.map