Omit extracting subfolder from a workspace URL
parent
7c598014a2
commit
e35377a56b
|
|
@ -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<String, String> 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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ public class GithubURLParser {
|
|||
this.githubPattern =
|
||||
compile(
|
||||
format(
|
||||
"^%s/(?<repoUser>[^/]++)/(?<repoName>[^/]++)((/)|(?:/tree/(?<branchName>[^/]++)(?:/(?<subFolder>.*))?)|(/pull/(?<pullRequestId>[^/]++)))?$",
|
||||
"^%s/(?<repoUser>[^/]+)/(?<repoName>[^/]++)((/)|(?:/tree/(?<branchName>.++))|(/pull/(?<pullRequestId>\\d++)))?$",
|
||||
endpoint));
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +173,6 @@ public class GithubURLParser {
|
|||
.withDisableSubdomainIsolation(disableSubdomainIsolation)
|
||||
.withBranch(branchName)
|
||||
.withLatestCommit(latestCommit)
|
||||
.withSubfolder(matcher.group("subFolder"))
|
||||
.withDevfileFilenames(devfileFilenamesProvider.getConfiguredDevfileFilenames())
|
||||
.withUrl(url);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,32 +115,19 @@ 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/tree/master/dashboard/",
|
||||
"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"
|
||||
}
|
||||
{"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"}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<String> 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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class GitlabUrlParser {
|
|||
private final PersonalAccessTokenManager personalAccessTokenManager;
|
||||
private static final List<String> gitlabUrlPatternTemplates =
|
||||
List.of(
|
||||
"^(?<host>%s)/(?<subgroups>([^/]++/?)+)/-/tree/(?<branch>[^/]++)(/)?(?<subfolder>[^/]++)?",
|
||||
"^(?<host>%s)/(?<subgroups>([^/]++/?)+)/-/tree/(?<branch>.++)(/)?",
|
||||
"^(?<host>%s)/(?<subgroups>.*)"); // a wider one, should be the last in the
|
||||
// list
|
||||
private final List<Pattern> gitlabUrlPatterns = new ArrayList<>();
|
||||
|
|
@ -168,23 +168,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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,28 @@ 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/-/tree/master/", "project", "user/project", "master", 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/subfolder",
|
||||
"repo",
|
||||
"user/project/repo",
|
||||
"foo",
|
||||
"subfolder"
|
||||
"foo"
|
||||
},
|
||||
{
|
||||
"https://gitlab1.com/user/project/group1/group2/repo/-/tree/foo/subfolder",
|
||||
"repo",
|
||||
"user/project/group1/group2/repo",
|
||||
"foo",
|
||||
"subfolder"
|
||||
"foo"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue