fix(clustertool): Try to harden the repo url generator a tad

This commit is contained in:
Kjeld Schouten
2024-11-08 21:57:37 +01:00
parent d41c3a8c05
commit 86fb83c9ac
+8 -3
View File
@@ -116,15 +116,20 @@ func FormatGitURL(input string) string {
// Remove "https://" prefix if present
input = strings.TrimPrefix(input, "https://")
if !strings.HasPrefix(input, "ssh://") {
input = "ssh://" + input
}
// Ensure input starts with "ssh://git@"
if !strings.HasPrefix(input, "ssh://git@") {
// Prepend "ssh://git@" if neither "ssh://" nor "git@" is present
if !strings.HasPrefix(input, "ssh://") {
input = "ssh://" + input
}
input = strings.Replace(input, "ssh://", "ssh://git@", 1)
}
if strings.Contains(url, "git@git@") {
input = strings.Replace(input, "git@git@", "git@", 1)
}
// Compile a regex to match and replace the URL pattern
re := regexp.MustCompile(`^ssh://git@([^:/]+)([:/])([\w-]+)/([\w-]+)\.git$`)
matches := re.FindStringSubmatch(input)