Skip to content

Commit ab338ce

Browse files
authored
Respect SSH urls without port (#810)
1 parent b720ce4 commit ab338ce

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsURLParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class AzureDevOpsURLParser {
5454
private final String azureSSHDevOpsPatternTemplate =
5555
"^git@ssh\\.%s:v3/(?<organization>.*)/(?<project>.*)/(?<repoName>.*)$";
5656
private final String azureSSHDevOpsServerPatternTemplate =
57-
"^ssh://%s:22/(?<organization>.*)/(?<project>.*)/_git/(?<repoName>.*)$";
57+
"^ssh://%s(:\\d*)?/(?<organization>.*)/(?<project>.*)/_git/(?<repoName>.*)$";
5858
private final String azureDevOpsPatternTemplate =
5959
"^https?://(?<organizationCanIgnore>[^@]++)?@?%s/(?<organization>[^/]++)/((?<project>[^/]++)/)?_git/"
6060
+ "(?<repoName>[^?]++)"
@@ -119,7 +119,10 @@ private Optional<String> getServerUrl(String repositoryUrl) {
119119
substring = repositoryUrl.substring(6);
120120
}
121121
if (!isNullOrEmpty(substring)) {
122-
return Optional.of("https://" + substring.substring(0, substring.indexOf(":")));
122+
return Optional.of(
123+
"https://"
124+
+ substring.substring(
125+
0, substring.contains(":") ? substring.indexOf(":") : substring.indexOf("/")));
123126
}
124127
// Otherwise, extract the base url from the given repository url by cutting the url after the
125128
// first slash.

wsmaster/che-core-api-factory-azure-devops/src/test/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsURLParserTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ public Object[][] expectedServerParsing() {
268268
"main",
269269
null
270270
},
271+
{
272+
"ssh://dev.azure-server.com/MyOrg/MyProject/_git/MyRepo",
273+
"MyOrg",
274+
"MyProject",
275+
"MyRepo",
276+
null,
277+
null
278+
},
271279
{
272280
"ssh://dev.azure-server.com:22/MyOrg/MyProject/_git/MyRepo",
273281
"MyOrg",

wsmaster/che-core-api-factory-bitbucket-server/src/main/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketServerURLParser.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public class BitbucketServerURLParser {
5757
"^(?<scheme>%s)://(?<host>%s)/users/(?<user>[^/]+)/repos/(?<repo>[^/]+)/?",
5858
"^(?<scheme>%s)://(?<host>%s)/scm/(?<project>[^/~]+)/(?<repo>[^/]+).git",
5959
"^(?<scheme>%s)://(?<host>%s)/projects/(?<project>[^/]+)/repos/(?<repo>[^/]+)/browse(\\?at=(?<branch>.*))?",
60-
"^(?<scheme>%s)://git@(?<host>%s):(?<port>\\d*)/~(?<user>[^/]+)/(?<repo>.*).git$",
61-
"^(?<scheme>%s)://git@(?<host>%s):(?<port>\\d*)/(?<project>[^/]+)/(?<repo>.*).git$");
60+
"^(?<scheme>%s)://git@(?<host>%s):?(?<port>\\d*)?/~(?<user>[^/]+)/(?<repo>.*).git$",
61+
"^(?<scheme>%s)://git@(?<host>%s):?(?<port>\\d*)?/(?<project>[^/]+)/(?<repo>.*).git$");
6262
private final List<Pattern> bitbucketUrlPatterns = new ArrayList<>();
6363
private static final String OAUTH_PROVIDER_NAME = "bitbucket-server";
6464

@@ -152,7 +152,9 @@ private boolean isApiRequestRelevant(String repositoryUrl) {
152152
private String getServerUrl(String repositoryUrl) {
153153
if (repositoryUrl.startsWith("ssh://git@")) {
154154
String substring = repositoryUrl.substring(10);
155-
return "https://" + substring.substring(0, substring.indexOf(":"));
155+
return "https://"
156+
+ substring.substring(
157+
0, substring.contains(":") ? substring.indexOf(":") : substring.indexOf("/"));
156158
}
157159
return repositoryUrl.substring(
158160
0,

wsmaster/che-core-api-factory-bitbucket-server/src/test/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketServerURLParserTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ public Object[][] urls() {
215215
{"https://bitbucket.2mcl.com/users/user/repos/repo/"},
216216
{"https://bbkt.com/scm/project/test1.git"},
217217
{"ssh://[email protected]:12345/~user/repo.git"},
218-
{"ssh://[email protected]:12345/project/test1.git"}
218+
{"ssh://[email protected]:12345/project/test1.git"},
219+
{"ssh://[email protected]/~user/repo.git"},
220+
{"ssh://[email protected]/project/test1.git"}
219221
};
220222
}
221223

0 commit comments

Comments
 (0)