diff options
Diffstat (limited to 'makima/src/bin/makima.rs')
| -rw-r--r-- | makima/src/bin/makima.rs | 77 |
1 files changed, 63 insertions, 14 deletions
diff --git a/makima/src/bin/makima.rs b/makima/src/bin/makima.rs index 29388e1..67eefc6 100644 --- a/makima/src/bin/makima.rs +++ b/makima/src/bin/makima.rs @@ -962,24 +962,44 @@ async fn run_tui_loop( Ok(result) => { let contract_name = result.0.get("name") .and_then(|v| v.as_str()) - .unwrap_or(&name); - app.status_message = Some(format!("Created contract: {}", contract_name)); + .unwrap_or(&name) + .to_string(); + let contract_id = result.0.get("id") + .and_then(|v| v.as_str()) + .and_then(|s| uuid::Uuid::parse_str(s).ok()); + + // Add repository if provided + if let (Some(repo_url), Some(cid)) = (repository_url.as_ref(), contract_id) { + if !repo_url.is_empty() { + // Extract repo name from URL (e.g., "owner/repo" from GitHub URL) + let repo_name = extract_repo_name(repo_url); + match client.add_remote_repository(cid, &repo_name, repo_url, true).await { + Ok(_) => { + app.status_message = Some(format!( + "Created contract '{}' with repository", + contract_name + )); + } + Err(e) => { + app.status_message = Some(format!( + "Created contract but failed to add repository: {}", + e + )); + } + } + } else { + app.status_message = Some(format!("Created contract: {}", contract_name)); + } + } else { + app.status_message = Some(format!("Created contract: {}", contract_name)); + } // Refresh the contracts list match load_contracts(client).await { Ok(items) => app.set_items(items), - Err(e) => app.status_message = Some(format!("Created but refresh failed: {}", e)), - } - - // TODO: If repository_url was provided, add it to the contract - if let Some(repo_url) = repository_url { - if !repo_url.is_empty() { - // We'd need to add a method to add repository to contract - // For now, just note it in the status - app.status_message = Some(format!( - "Created contract: {} (Note: Add repository {} manually)", - contract_name, repo_url - )); + Err(e) => { + let msg = app.status_message.take().unwrap_or_default(); + app.status_message = Some(format!("{} (refresh failed: {})", msg, e)); } } } @@ -1070,6 +1090,35 @@ async fn run_tui_loop( Ok(None) } +/// Extract a repository name from a URL. +/// E.g., "https://github.com/owner/repo.git" -> "owner/repo" +fn extract_repo_name(url: &str) -> String { + // Remove .git suffix if present + let url = url.trim_end_matches(".git"); + + // Try to extract owner/repo from common Git hosting URLs + if let Some(path) = url.strip_prefix("https://github.com/") + .or_else(|| url.strip_prefix("https://gitlab.com/")) + .or_else(|| url.strip_prefix("https://bitbucket.org/")) + .or_else(|| url.strip_prefix("git@github.com:")) + .or_else(|| url.strip_prefix("git@gitlab.com:")) + .or_else(|| url.strip_prefix("git@bitbucket.org:")) + { + // Return owner/repo + return path.to_string(); + } + + // Fallback: try to get the last path segment + if let Some(last_segment) = url.rsplit('/').next() { + if !last_segment.is_empty() { + return last_segment.to_string(); + } + } + + // Last resort: use the full URL as the name + url.to_string() +} + /// Parse an output entry from the API response into an OutputLine fn parse_output_entry(entry: &serde_json::Value) -> Option<OutputLine> { let message_type = entry.get("messageType") |
