Skip to content

Commit ff012a1

Browse files
author
Antigravity Subagent
committed
fix(cli): support mixed-case GitHub hostnames in PR command
1 parent 7954d02 commit ff012a1

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

src/cortex-cli/src/pr_cmd.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,20 +452,23 @@ fn get_git_remote_url() -> Result<String> {
452452

453453
/// Parse a GitHub URL to extract owner and repo.
454454
fn parse_github_url(url: &str) -> Result<(String, String)> {
455+
let url_lower = url.to_lowercase();
456+
455457
// Handle SSH URLs: git@github.com:owner/repo.git
456-
if url.starts_with("git@github.com:") {
457-
let path = url.trim_start_matches("git@github.com:");
458-
let path = path.trim_end_matches(".git");
458+
if url_lower.starts_with("git@github.com:") {
459+
let path = &url[15..]; // Skip "git@github.com:" preserving case
460+
let path = path.strip_suffix(".git").unwrap_or(path);
459461
let parts: Vec<&str> = path.split('/').collect();
460462
if parts.len() >= 2 {
461463
return Ok((parts[0].to_string(), parts[1].to_string()));
462464
}
463465
}
464466

465467
// Handle HTTPS URLs: https://github.com/owner/repo.git
466-
if url.contains("github.com") {
467-
let url = url.trim_end_matches(".git");
468-
let parts: Vec<&str> = url.split('/').collect();
468+
if let Some(pos) = url_lower.find("github.com/") {
469+
let path = &url[pos + 11..]; // Skip "github.com/" preserving case
470+
let path = path.strip_suffix(".git").unwrap_or(path);
471+
let parts: Vec<&str> = path.split('/').collect();
469472
if parts.len() >= 2 {
470473
let repo = parts[parts.len() - 1];
471474
let owner = parts[parts.len() - 2];
@@ -516,4 +519,18 @@ mod tests {
516519
assert_eq!(owner, "cortex-ai");
517520
assert_eq!(repo, "cortex");
518521
}
522+
523+
#[test]
524+
fn test_parse_github_url_mixed_case() {
525+
let (owner, repo) = parse_github_url("https://GitHub.com/CortexLM/cortex.git").unwrap();
526+
assert_eq!(owner, "CortexLM");
527+
assert_eq!(repo, "cortex");
528+
}
529+
530+
#[test]
531+
fn test_parse_github_url_ssh_mixed_case() {
532+
let (owner, repo) = parse_github_url("git@GitHub.com:CortexLM/cortex.git").unwrap();
533+
assert_eq!(owner, "CortexLM");
534+
assert_eq!(repo, "cortex");
535+
}
519536
}

0 commit comments

Comments
 (0)