Skip to main content

vibe_workspace/git/
mod.rs

1use serde::{Deserialize, Serialize};
2use std::path::PathBuf;
3
4pub mod bulk_clone;
5pub mod clone;
6pub mod provider;
7pub mod search;
8
9pub use clone::CloneCommand;
10pub use search::SearchCommand;
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct Repository {
14    pub id: String,
15    pub name: String,
16    pub full_name: String, // org/repo
17    pub description: Option<String>,
18    pub url: String,
19    pub ssh_url: String,
20    pub stars: u32,
21    pub language: Option<String>,
22    pub license: Option<String>, // License key (e.g., "mit", "apache-2.0")
23    pub topics: Vec<String>,
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
27pub enum SortMethod {
28    #[default]
29    BestMatch,
30    Stars,
31    Forks,
32    Updated,
33}
34
35impl SortMethod {
36    pub fn as_str(&self) -> &'static str {
37        match self {
38            SortMethod::BestMatch => "best-match",
39            SortMethod::Stars => "stars",
40            SortMethod::Forks => "forks",
41            SortMethod::Updated => "updated",
42        }
43    }
44
45    pub fn display_name(&self) -> &'static str {
46        match self {
47            SortMethod::BestMatch => "Best Match",
48            SortMethod::Stars => "Most Stars",
49            SortMethod::Forks => "Most Forks",
50            SortMethod::Updated => "Recently Updated",
51        }
52    }
53}
54
55#[derive(Debug, Clone)]
56pub struct SearchQuery {
57    pub keywords: Vec<String>,
58    pub tags: Vec<String>,
59    pub language: Option<String>,
60    pub organization: Option<String>,
61    pub limit: Option<usize>,
62    pub sort: SortMethod,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct GitConfig {
67    pub default_clone_location: PathBuf,
68    pub standardize_paths: bool,
69    pub auto_install_dependencies: bool,
70    pub search_providers: Vec<String>,
71}
72
73impl Default for GitConfig {
74    fn default() -> Self {
75        Self {
76            default_clone_location: dirs::home_dir().unwrap_or_default().join("Workspace"),
77            standardize_paths: true,
78            auto_install_dependencies: false,
79            search_providers: vec!["github_cli".to_string()],
80        }
81    }
82}
83
84#[derive(Debug, thiserror::Error)]
85pub enum GitError {
86    #[error("Repository already exists at {path}")]
87    RepositoryExists { path: PathBuf },
88
89    #[error("Invalid Git URL: {url}")]
90    InvalidUrl { url: String },
91
92    #[error("GitHub CLI not found. Please install 'gh' command.")]
93    GitHubCliNotFound,
94
95    #[error("Search returned no results for query: {query}")]
96    NoSearchResults { query: String },
97
98    #[error("Clone failed: {message}")]
99    CloneFailed { message: String },
100
101    #[error("Search provider error: {provider}")]
102    ProviderError {
103        provider: String,
104        source: anyhow::Error,
105    },
106}