fix: detect SSH remotes with non-git user prefixes (e.g. gitlab@) (#3649)
This commit is contained in:
1 parent
dc0ff8f13e
commit
7ce4194707
6 files changed
+72
-16
No files matched your search
@@ -133,19 +133,22 @@ export function getChangeRequestTerminologyForKind(
|
||||
};
|
||||
}
|
||||
|
||||
const SCP_SSH_REMOTE_PATTERN = /^[a-zA-Z0-9._-]+@([^:/]+):/;
|
||||
|
||||
export function isSshRemoteUrl(remoteUrl: string): boolean {
|
||||
const trimmed = remoteUrl.trim();
|
||||
return SCP_SSH_REMOTE_PATTERN.test(trimmed) || trimmed.toLowerCase().startsWith("ssh://");
|
||||
}
|
||||
|
||||
function parseRemoteHost(remoteUrl: string): string | null {
|
||||
const trimmed = remoteUrl.trim();
|
||||
if (trimmed.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (trimmed.startsWith("git@")) {
|
||||
const hostWithPath = trimmed.slice("git@".length);
|
||||
const separatorIndex = hostWithPath.search(/[:/]/);
|
||||
if (separatorIndex <= 0) {
|
||||
return null;
|
||||
}
|
||||
return hostWithPath.slice(0, separatorIndex).toLowerCase();
|
||||
const scpMatch = SCP_SSH_REMOTE_PATTERN.exec(trimmed);
|
||||
if (scpMatch?.[1]) {
|
||||
return scpMatch[1].toLowerCase();
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user