diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java index 0387e059bd..f8d6b03f84 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java @@ -26,6 +26,9 @@ public class GitUtils { public static final Pattern URL_PATTERN_WITHOUT_SCHEME = Pattern.compile("^git@(?.+?):/*(?.+?)(\\.git)?$"); + public static final Pattern URL_PATTERN_WITH_CUSTOM_USERNAME = + Pattern.compile("^(ssh://)?[a-zA-Z0-9]+@(?.+?):/*(?.+?)(\\\\.git)?$"); + /** * Sample repo urls : * git@example.com:user/repoName.git @@ -45,6 +48,10 @@ public class GitUtils { match = URL_PATTERN_WITHOUT_SCHEME.matcher(sshUrl); } + if (!match.matches()) { + match = URL_PATTERN_WITH_CUSTOM_USERNAME.matcher(sshUrl); + } + if (!match.matches()) { throw new AppsmithException( AppsmithError.INVALID_GIT_CONFIGURATION, diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitUtilsTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitUtilsTest.java index 0409ec3152..f388da74cf 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitUtilsTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitUtilsTest.java @@ -60,6 +60,14 @@ public class GitUtilsTest { assertThat(GitUtils.convertSshUrlToBrowserSupportedUrl( "ssh://git@tim.tam.example.com:9876/v3/sladeping/pyhe/SpaceJunk")) .isEqualTo("https://tim.tam.example.com/v3/sladeping/pyhe/SpaceJunk"); + + // custom ssh username: + assertThat(GitUtils.convertSshUrlToBrowserSupportedUrl("custom@vs-ssh.visualstudio.com:v3/newJet/ai/zilla")) + .isEqualTo("https://vs-ssh.visualstudio.com/v3/newJet/ai/zilla"); + + assertThat(GitUtils.convertSshUrlToBrowserSupportedUrl( + "ssh://custom@vs-ssh.visualstudio.com:v3/newJet/ai/zilla")) + .isEqualTo("https://vs-ssh.visualstudio.com/v3/newJet/ai/zilla"); } @Test @@ -131,6 +139,13 @@ public class GitUtilsTest { assertThat(GitUtils.getRepoName("user@host.xz:path/to/repo.git")).isEqualTo("repo"); assertThat(GitUtils.getRepoName("org-987654321@github.com:org_name/repository_name.git")) .isEqualTo("repository_name"); + + // custom ssh username: + assertThat(GitUtils.getRepoName("custom@vs-ssh.visualstudio.com:v3/newJet/ai/zilla")) + .isEqualTo("zilla"); + + assertThat(GitUtils.getRepoName("ssh://custom@vs-ssh.visualstudio.com:v3/newJet/ai/zilla")) + .isEqualTo("zilla"); } @Test