fix: added regex (#33426)

## Description
> Added regex for supporting custom usernames in ssh

Fixes #19881
## Automation

/ok-to-test tags="@tag.Git"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9090239144>
> Commit: 05f2b6f8e6bbbbd6f05e70d9fa9194a07c89d86d
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9090239144&attempt=1"
target="_blank">Click here!</a>

<!-- end of auto-generated comment: Cypress test results  -->






## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
This commit is contained in:
Manish Kumar 2024-05-15 11:04:32 +05:30 committed by sondermanish
parent f22172724c
commit 9bcec069b9
2 changed files with 22 additions and 0 deletions

View File

@ -26,6 +26,9 @@ public class GitUtils {
public static final Pattern URL_PATTERN_WITHOUT_SCHEME =
Pattern.compile("^git@(?<host>.+?):/*(?<path>.+?)(\\.git)?$");
public static final Pattern URL_PATTERN_WITH_CUSTOM_USERNAME =
Pattern.compile("^(ssh://)?[a-zA-Z0-9]+@(?<host>.+?):/*(?<path>.+?)(\\\\.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,

View File

@ -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