Skip to content

Commit 00be4c5

Browse files
unhappychoiceclaude
andcommitted
refactor: remove duplicate URL parsing logic in LocalGitRepositoryClient
- Remove parse_repo_info method - Use GitRepositoryRefParser::parse directly in create_from_local_path - Eliminate code duplication and improve consistency 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5948df3 commit 00be4c5

File tree

1 file changed

+3
-30
lines changed

1 file changed

+3
-30
lines changed

src/infrastructure/git/local/local_git_repository_client.rs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ impl LocalGitRepositoryClient {
127127
.to_string();
128128
("local".to_string(), repo_name)
129129
} else {
130-
Self::parse_repo_info(&remote_url)
130+
GitRepositoryRefParser::parse(&remote_url)
131+
.map(|repo_ref| (repo_ref.owner, repo_ref.name))
132+
.unwrap_or_else(|_| ("unknown".to_string(), "unknown".to_string()))
131133
};
132134

133135
// Get current branch
@@ -159,33 +161,4 @@ impl LocalGitRepositoryClient {
159161
root_path: Some(path.to_path_buf()),
160162
})
161163
}
162-
163-
/// Parse repository info from URL
164-
fn parse_repo_info(url: &str) -> (String, String) {
165-
// Try to extract owner/repo from URL
166-
if let Some(ssh_part) = url.strip_prefix("git@") {
167-
if let Some(colon_pos) = ssh_part.find(':') {
168-
let path = &ssh_part[colon_pos + 1..];
169-
let parts: Vec<&str> = path.trim_end_matches(".git").split('/').collect();
170-
if parts.len() >= 2 {
171-
return (parts[0].to_string(), parts[1].to_string());
172-
}
173-
}
174-
}
175-
176-
if let Some(url_without_protocol) = url
177-
.strip_prefix("https://")
178-
.or_else(|| url.strip_prefix("http://"))
179-
{
180-
let parts: Vec<&str> = url_without_protocol.split('/').collect();
181-
if parts.len() >= 3 {
182-
return (
183-
parts[1].to_string(),
184-
parts[2].trim_end_matches(".git").to_string(),
185-
);
186-
}
187-
}
188-
189-
("unknown".to_string(), "unknown".to_string())
190-
}
191164
}

0 commit comments

Comments
 (0)