fix: Update cleanUrl method to handle ssh URLs

This commit is contained in:
lisiur 2024-05-22 14:43:25 +08:00
parent 647cbb3cac
commit 038dba6710

View File

@ -381,6 +381,13 @@ export class BaseBranch {
private cleanUrl(url: string): string { private cleanUrl(url: string): string {
if (url.startsWith('http')) { if (url.startsWith('http')) {
return url.replace('.git', '').trim(); return url.replace('.git', '').trim();
} else if (url.startsWith('ssh')) {
url = url.replace('ssh://git@', '');
const [host, ...paths] = url.split('/');
const path = paths.join('/').replace('.git', '');
const protocol = /\d+\.\d+\.\d+\.\d+/.test(host) ? 'http' : 'https';
const [hostname, _port] = host.split(':');
return `${protocol}://${hostname}/${path}`
} else { } else {
return url.replace(':', '/').replace('git@', 'https://').replace('.git', '').trim(); return url.replace(':', '/').replace('git@', 'https://').replace('.git', '').trim();
} }