diff --git a/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubSourceStorageBuilder.java b/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubSourceStorageBuilder.java index 18719bfd52..ff99c34f87 100644 --- a/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubSourceStorageBuilder.java +++ b/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubSourceStorageBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2021 Red Hat, Inc. + * Copyright (c) 2012-2023 Red Hat, Inc. * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -13,7 +13,6 @@ package org.eclipse.che.api.factory.server.github; import static org.eclipse.che.dto.server.DtoFactory.newDto; -import com.google.common.base.Strings; import java.util.HashMap; import java.util.Map; import javax.inject.Singleton; @@ -40,9 +39,6 @@ public class GithubSourceStorageBuilder { Map parameters = new HashMap<>(2); parameters.put("branch", githubUrl.getBranch()); - if (!Strings.isNullOrEmpty(githubUrl.getSubfolder())) { - parameters.put("keepDir", githubUrl.getSubfolder()); - } return newDto(SourceStorageDto.class) .withLocation(githubUrl.repositoryLocation()) .withType("github") @@ -59,7 +55,6 @@ public class GithubSourceStorageBuilder { return newDto(SourceDto.class) .withLocation(githubUrl.repositoryLocation()) .withType("github") - .withBranch(githubUrl.getBranch()) - .withSparseCheckoutDir(githubUrl.getSubfolder()); + .withBranch(githubUrl.getBranch()); } } 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 bd71791a6a..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 @@ -99,20 +99,20 @@ public class GithubURLParser { this.githubPattern = compile( format( - "^%s/(?[^/]++)/(?[^/]++)((/)|(?:/tree/(?[^/]++)(?:/(?.*))?)|(/pull/(?[^/]++)))?$", + "^%s/(?[^/]+)/(?[^/]++)((/)|(?:/tree/(?.++))|(/pull/(?\\d++)))?$", endpoint)); } 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 { @@ -173,7 +173,6 @@ public class GithubURLParser { .withDisableSubdomainIsolation(disableSubdomainIsolation) .withBranch(branchName) .withLatestCommit(latestCommit) - .withSubfolder(matcher.group("subFolder")) .withDevfileFilenames(devfileFilenamesProvider.getConfiguredDevfileFilenames()) .withUrl(url); } diff --git a/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubUrl.java b/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubUrl.java index d00cd7c7f5..46ea5be275 100644 --- a/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubUrl.java +++ b/wsmaster/che-core-api-factory-github/src/main/java/org/eclipse/che/api/factory/server/github/GithubUrl.java @@ -46,9 +46,6 @@ public class GithubUrl extends DefaultFactoryUrl { /** SHA of the latest commit in the current branch */ private String latestCommit; - /** Subfolder if any */ - private String subfolder; - private String serverUrl; private boolean disableSubdomainIsolation; @@ -143,26 +140,6 @@ public class GithubUrl extends DefaultFactoryUrl { return this; } - /** - * Gets subfolder of this github url - * - * @return the subfolder part - */ - public String getSubfolder() { - return this.subfolder; - } - - /** - * Sets the subfolder represented by the URL. - * - * @param subfolder path inside the repository - * @return current github instance - */ - protected GithubUrl withSubfolder(String subfolder) { - this.subfolder = subfolder; - return this; - } - public GithubUrl withServerUrl(String serverUrl) { this.serverUrl = serverUrl; return this; diff --git a/wsmaster/che-core-api-factory-github/src/test/java/org/eclipse/che/api/factory/server/github/GithubURLParserTest.java b/wsmaster/che-core-api-factory-github/src/test/java/org/eclipse/che/api/factory/server/github/GithubURLParserTest.java index 5a16e81e7b..42a97931a4 100644 --- a/wsmaster/che-core-api-factory-github/src/test/java/org/eclipse/che/api/factory/server/github/GithubURLParserTest.java +++ b/wsmaster/che-core-api-factory-github/src/test/java/org/eclipse/che/api/factory/server/github/GithubURLParserTest.java @@ -76,15 +76,13 @@ public class GithubURLParserTest { /** Compare parsing */ @Test(dataProvider = "parsing") - public void checkParsing( - String url, String username, String repository, String branch, String subfolder) + public void checkParsing(String url, String username, String repository, String branch) throws ApiException { GithubUrl githubUrl = githubUrlParser.parse(url); assertEquals(githubUrl.getUsername(), username); assertEquals(githubUrl.getRepository(), repository); assertEquals(githubUrl.getBranch(), branch); - assertEquals(githubUrl.getSubfolder(), subfolder); } /** Compare parsing */ @@ -117,31 +115,24 @@ public class GithubURLParserTest { @DataProvider(name = "parsing") public Object[][] expectedParsing() { return new Object[][] { - {"https://github.com/eclipse/che", "eclipse", "che", null, null}, - {"https://github.com/eclipse/che123", "eclipse", "che123", null, null}, - {"https://github.com/eclipse/che.git", "eclipse", "che", null, null}, - {"https://github.com/eclipse/che.with.dot.git", "eclipse", "che.with.dot", null, null}, - {"https://github.com/eclipse/-.git", "eclipse", "-", null, null}, - {"https://github.com/eclipse/-j.git", "eclipse", "-j", null, null}, - {"https://github.com/eclipse/-", "eclipse", "-", null, null}, - {"https://github.com/eclipse/che-with-hyphen", "eclipse", "che-with-hyphen", null, null}, - {"https://github.com/eclipse/che-with-hyphen.git", "eclipse", "che-with-hyphen", null, null}, - {"https://github.com/eclipse/che/", "eclipse", "che", null, null}, - {"https://github.com/eclipse/repositorygit", "eclipse", "repositorygit", null, null}, - {"https://github.com/eclipse/che/tree/4.2.x", "eclipse", "che", "4.2.x", null}, + {"https://github.com/eclipse/che", "eclipse", "che", null}, + {"https://github.com/eclipse/che123", "eclipse", "che123", null}, + {"https://github.com/eclipse/che.git", "eclipse", "che", null}, + {"https://github.com/eclipse/che.with.dot.git", "eclipse", "che.with.dot", null}, + {"https://github.com/eclipse/-.git", "eclipse", "-", null}, + {"https://github.com/eclipse/-j.git", "eclipse", "-j", null}, + {"https://github.com/eclipse/-", "eclipse", "-", null}, + {"https://github.com/eclipse/che-with-hyphen", "eclipse", "che-with-hyphen", null}, + {"https://github.com/eclipse/che-with-hyphen.git", "eclipse", "che-with-hyphen", null}, + {"https://github.com/eclipse/che/", "eclipse", "che", null}, + {"https://github.com/eclipse/repositorygit", "eclipse", "repositorygit", null}, + {"https://github.com/eclipse/che/tree/4.2.x", "eclipse", "che", "4.2.x"}, + {"https://github.com/eclipse/che/tree/master", "eclipse", "che", "master"}, { - "https://github.com/eclipse/che/tree/master/dashboard/", + "https://github.com/eclipse/che/tree/branch/with/slash", "eclipse", "che", - "master", - "dashboard/" - }, - { - "https://github.com/eclipse/che/tree/master/plugins/plugin-git/che-plugin-git-ext-git", - "eclipse", - "che", - "master", - "plugins/plugin-git/che-plugin-git-ext-git" + "branch/with/slash" } }; } diff --git a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabFactoryParametersResolver.java b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabFactoryParametersResolver.java index c420da0ea9..cdbf4a0204 100644 --- a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabFactoryParametersResolver.java +++ b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabFactoryParametersResolver.java @@ -136,8 +136,7 @@ public class GitlabFactoryParametersResolver extends RawDevfileUrlFactoryParamet newDto(SourceDto.class) .withLocation(gitlabUrl.repositoryLocation()) .withType("git") - .withBranch(gitlabUrl.getBranch()) - .withSparseCheckoutDir(gitlabUrl.getSubfolder())) + .withBranch(gitlabUrl.getBranch())) .withName(gitlabUrl.getProject()), project -> { final String location = project.getSource().getLocation(); diff --git a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrl.java b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrl.java index 1e581bc255..057630821a 100644 --- a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrl.java +++ b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabUrl.java @@ -49,9 +49,6 @@ public class GitlabUrl extends DefaultFactoryUrl { /** Branch name */ private String branch; - /** Subfolder if any */ - private String subfolder; - /** Devfile filenames list */ private final List devfileFilenames = new ArrayList<>(); @@ -129,26 +126,6 @@ public class GitlabUrl extends DefaultFactoryUrl { return this; } - /** - * Gets subfolder of this gitlab url - * - * @return the subfolder part - */ - public String getSubfolder() { - return this.subfolder; - } - - /** - * Sets the subfolder represented by the URL. - * - * @param subfolder path inside the repository - * @return current gitlab URL instance - */ - protected GitlabUrl withSubfolder(String subfolder) { - this.subfolder = subfolder; - return this; - } - /** * Provides list of configured devfile filenames with locations * 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 f25cbd7f8e..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 @@ -46,7 +46,7 @@ public class GitlabUrlParser { private final PersonalAccessTokenManager personalAccessTokenManager; private static final List gitlabUrlPatternTemplates = List.of( - "^(?%s)/(?([^/]++/?)+)/-/tree/(?[^/]++)(/)?(?[^/]++)?", + "^(?%s)/(?([^/]++/?)+)/-/tree/(?.++)(/)?", "^(?%s)/(?.*)"); // a wider one, should be the last in the // list private final List gitlabUrlPatterns = new ArrayList<>(); @@ -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." @@ -168,23 +169,16 @@ public class GitlabUrlParser { } String branch = null; - String subfolder = null; try { branch = matcher.group("branch"); } catch (IllegalArgumentException e) { // ok no such group } - try { - subfolder = matcher.group("subfolder"); - } catch (IllegalArgumentException e) { - // ok no such group - } return new GitlabUrl() .withHostName(host) .withSubGroups(subGroups) .withBranch(branch) - .withSubfolder(subfolder) .withDevfileFilenames(devfileFilenamesProvider.getConfiguredDevfileFilenames()); } } 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 c9e13812d2..27aadf7c2a 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 @@ -71,14 +71,12 @@ public class GitlabUrlParserTest { /** Compare parsing */ @Test(dataProvider = "parsing") - public void checkParsing( - String url, String project, String subGroups, String branch, String subfolder) { + public void checkParsing(String url, String project, String subGroups, String branch) { GitlabUrl gitlabUrl = gitlabUrlParser.parse(url); assertEquals(gitlabUrl.getProject(), project); assertEquals(gitlabUrl.getSubGroups(), subGroups); assertEquals(gitlabUrl.getBranch(), branch); - assertEquals(gitlabUrl.getSubfolder(), subfolder); } @Test @@ -123,33 +121,29 @@ public class GitlabUrlParserTest { @DataProvider(name = "parsing") public Object[][] expectedParsing() { return new Object[][] { - {"https://gitlab1.com/user/project1.git", "project1", "user/project1", null, null}, - {"https://gitlab1.com/user/project/test1.git", "test1", "user/project/test1", null, null}, + {"https://gitlab1.com/user/project1.git", "project1", "user/project1", null}, + {"https://gitlab1.com/user/project/test1.git", "test1", "user/project/test1", null}, { "https://gitlab1.com/user/project/group1/group2/test1.git", "test1", "user/project/group1/group2/test1", - null, null }, - {"https://gitlab1.com/user/project/", "project", "user/project", null, null}, - {"https://gitlab1.com/user/project/repo/", "repo", "user/project/repo", null, null}, + {"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/-/tree/master/", "project", "user/project", "master", null - }, - { - "https://gitlab1.com/user/project/repo/-/tree/foo/subfolder", + "https://gitlab1.com/user/project/repo/-/tree/branch/with/slash", "repo", "user/project/repo", - "foo", - "subfolder" + "branch/with/slash" }, { - "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", - "subfolder" + "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" - }, }; }