From bcc84f3a111f324e56f72e5a9852af6772f77b06 Mon Sep 17 00:00:00 2001 From: Igor Vinokur Date: Mon, 12 Jun 2023 16:34:12 +0300 Subject: [PATCH] fixup! Omit extracting subfolder from a workspace URL --- .../api/factory/server/github/GithubURLParser.java | 6 +++--- .../api/factory/server/gitlab/GitlabUrlParser.java | 11 ++++++----- .../factory/server/gitlab/GitlabUrlParserTest.java | 9 ++------- .../che/api/factory/server/gitlab/GitlabUrlTest.java | 4 ---- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubURLParser.java b/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubURLParser.java index a021c463c7..811853e51d 100644 --- a/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubURLParser.java +++ b/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubURLParser.java @@ -104,15 +104,15 @@ public class GithubURLParser { } public boolean isValid(@NotNull String url) { - return githubPattern.matcher(url).matches(); + return githubPattern.matcher(trimEnd(url, '/')).matches(); } public GithubUrl parseWithoutAuthentication(String url) throws ApiException { - return parse(url, false); + return parse(trimEnd(url, '/'), false); } public GithubUrl parse(String url) throws ApiException { - return parse(url, true); + return parse(trimEnd(url, '/'), true); } private GithubUrl parse(String url, boolean authenticationRequired) throws ApiException { diff --git a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlParser.java b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlParser.java index 58ceab195a..a561866262 100644 --- a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlParser.java +++ b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlParser.java @@ -93,7 +93,8 @@ public class GitlabUrlParser { } public boolean isValid(@NotNull String url) { - return gitlabUrlPatterns.stream().anyMatch(pattern -> pattern.matcher(url).matches()) + return gitlabUrlPatterns.stream() + .anyMatch(pattern -> pattern.matcher(trimEnd(url, '/')).matches()) // If the Gitlab URL is not configured, try to find it in a manually added user namespace // token. || isUserTokenPresent(url) @@ -144,15 +145,15 @@ public class GitlabUrlParser { * {@link GitlabUrl} objects. */ public GitlabUrl parse(String url) { - + String trimmedUrl = trimEnd(url, '/'); Optional matcherOptional = gitlabUrlPatterns.stream() - .map(pattern -> pattern.matcher(url)) + .map(pattern -> pattern.matcher(trimmedUrl)) .filter(Matcher::matches) .findFirst() - .or(() -> getPatternMatcherByUrl(url)); + .or(() -> getPatternMatcherByUrl(trimmedUrl)); if (matcherOptional.isPresent()) { - return parse(matcherOptional.get()).withUrl(url); + return parse(matcherOptional.get()).withUrl(trimmedUrl); } else { throw new UnsupportedOperationException( "The gitlab integration is not configured properly and cannot be used at this moment." diff --git a/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlParserTest.java b/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlParserTest.java index c893311d22..3843160a37 100644 --- a/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlParserTest.java +++ b/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlParserTest.java @@ -132,14 +132,9 @@ public class GitlabUrlParserTest { {"https://gitlab1.com/user/project/", "project", "user/project", null}, {"https://gitlab1.com/user/project/repo/", "repo", "user/project/repo", null}, {"https://gitlab1.com/user/project/-/tree/master/", "project", "user/project", "master"}, + {"https://gitlab1.com/user/project/repo/-/tree/foo", "repo", "user/project/repo", "foo"}, { - "https://gitlab1.com/user/project/repo/-/tree/foo/subfolder", - "repo", - "user/project/repo", - "foo" - }, - { - "https://gitlab1.com/user/project/group1/group2/repo/-/tree/foo/subfolder", + "https://gitlab1.com/user/project/group1/group2/repo/-/tree/foo/", "repo", "user/project/group1/group2/repo", "foo" diff --git a/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlTest.java b/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlTest.java index afcc2d9321..e03e5b49f1 100644 --- a/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlTest.java +++ b/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrlTest.java @@ -85,10 +85,6 @@ public class GitlabUrlTest { "https://gitlab.net/eclipse/fooproj/che/-/tree/foobranch/", "https://gitlab.net/api/v4/projects/eclipse%%2Ffooproj%%2Fche/repository/files/%s/raw?ref=foobranch" }, - { - "https://gitlab.net/eclipse/fooproj/che/-/tree/foobranch/subfolder", - "https://gitlab.net/api/v4/projects/eclipse%%2Ffooproj%%2Fche/repository/files/%s/raw?ref=foobranch" - }, }; }