Skip to content

Commit 689b038

Browse files
authored
Respect branch parameter when resolving a devfile (#828)
* Respect branch parameter when resolving a devfile * fixup! Respect branch parameter when resolving a devfile * fixup! Respect branch parameter when resolving a devfile
1 parent 15b60dc commit 689b038

File tree

32 files changed

+224
-114
lines changed

32 files changed

+224
-114
lines changed

build/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ build_image() {
200200
fi
201201

202202
printf "${BOLD}Building image ${IMAGE_NAME}${NC}\n"
203-
"${BUILDER}" build --platform ${BUILD_PLATFORMS} -f ${DIR}/.Dockerfile --manifest ${IMAGE_MANIFEST} .
203+
"${BUILDER}" build --platform ${BUILD_PLATFORMS} -t ${IMAGE_NAME} -f ${DIR}/.Dockerfile --manifest ${IMAGE_MANIFEST} .
204204
DOCKER_STATUS=$?
205205
if [ ! $DOCKER_STATUS -eq 0 ]; then
206206
printf "${RED}Failure when building docker image ${IMAGE_NAME}${NC}\n"

wsmaster/che-core-api-factory-azure-devops/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
<groupId>org.eclipse.che.core</groupId>
8383
<artifactId>che-core-api-workspace-shared</artifactId>
8484
</dependency>
85+
<dependency>
86+
<groupId>org.eclipse.che.core</groupId>
87+
<artifactId>che-core-commons-annotations</artifactId>
88+
</dependency>
8589
<dependency>
8690
<groupId>org.eclipse.che.core</groupId>
8791
<artifactId>che-core-commons-lang</artifactId>

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2024 Red Hat, Inc.
2+
* Copyright (c) 2012-2025 Red Hat, Inc.
33
* This program and the accompanying materials are made
44
* available under the terms of the Eclipse Public License 2.0
55
* which is available at https://www.eclipse.org/legal/epl-2.0/
@@ -11,6 +11,7 @@
1111
*/
1212
package org.eclipse.che.api.factory.server.azure.devops;
1313

14+
import static org.eclipse.che.api.factory.shared.Constants.REVISION_PARAMETER_NAME;
1415
import static org.eclipse.che.api.factory.shared.Constants.URL_PARAMETER_NAME;
1516
import static org.eclipse.che.dto.server.DtoFactory.newDto;
1617

@@ -82,7 +83,9 @@ public FactoryMetaDto createFactory(@NotNull final Map<String, String> factoryPa
8283
throws ApiException {
8384
// no need to check null value of url parameter as accept() method has performed the check
8485
final AzureDevOpsUrl azureDevOpsUrl =
85-
azureDevOpsURLParser.parse(factoryParameters.get(URL_PARAMETER_NAME));
86+
azureDevOpsURLParser.parse(
87+
factoryParameters.get(URL_PARAMETER_NAME),
88+
factoryParameters.get(REVISION_PARAMETER_NAME));
8689

8790
// create factory from the following location if location exists, else create default factory
8891
return createFactory(
@@ -118,7 +121,7 @@ public FactoryDevfileV2Dto visit(FactoryDevfileV2Dto factoryDto) {
118121

119122
@Override
120123
public RemoteFactoryUrl parseFactoryUrl(String factoryUrl) throws ApiException {
121-
return azureDevOpsURLParser.parse(factoryUrl);
124+
return azureDevOpsURLParser.parse(factoryUrl, null);
122125
}
123126

124127
private SourceStorageDto buildWorkspaceConfigSource(AzureDevOpsUrl azureDevOpsUrl) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2023 Red Hat, Inc.
2+
* Copyright (c) 2012-2025 Red Hat, Inc.
33
* This program and the accompanying materials are made
44
* available under the terms of the Eclipse Public License 2.0
55
* which is available at https://www.eclipse.org/legal/epl-2.0/
@@ -52,7 +52,7 @@ public boolean accept(@NotNull String repository) {
5252
@Override
5353
public String fileContent(@NotNull String repository, @NotNull String filePath)
5454
throws ApiException {
55-
final AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(repository);
55+
final AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(repository, null);
5656
try {
5757
return fetchContent(azureDevOpsUrl, filePath, false);
5858
} catch (DevfileException exception) {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.eclipse.che.api.factory.server.scm.exception.UnknownScmProviderException;
3333
import org.eclipse.che.api.factory.server.scm.exception.UnsatisfiedScmPreconditionException;
3434
import org.eclipse.che.api.factory.server.urlfactory.DevfileFilenamesProvider;
35+
import org.eclipse.che.commons.annotation.Nullable;
3536

3637
/**
3738
* Parser of String Azure DevOps URLs and provide {@link AzureDevOpsUrl} objects.
@@ -155,7 +156,7 @@ private IllegalArgumentException buildIllegalArgumentException(String url) {
155156
format("The given url %s is not a valid Azure DevOps URL. ", url));
156157
}
157158

158-
public AzureDevOpsUrl parse(String url) {
159+
public AzureDevOpsUrl parse(String url, @Nullable String revision) {
159160
Matcher matcher;
160161
boolean isHTTPSUrl = azureDevOpsPattern.matcher(url).matches();
161162
if (isHTTPSUrl) {
@@ -179,13 +180,13 @@ public AzureDevOpsUrl parse(String url) {
179180
project = repoName;
180181
}
181182

182-
String branch = null;
183+
String branchFromUrl = null;
183184
String tag = null;
184185

185186
String organization = matcher.group("organization");
186187
String urlToReturn = url;
187188
if (isHTTPSUrl) {
188-
branch = matcher.group("branch");
189+
branchFromUrl = matcher.group("branch");
189190
tag = matcher.group("tag");
190191
// The url might have the following formats:
191192
// - https://<organization>@<host>/<organization>/<project>/_git/<repoName>
@@ -207,7 +208,7 @@ public AzureDevOpsUrl parse(String url) {
207208
.withProject(project)
208209
.withRepository(repoName)
209210
.withOrganization(organization)
210-
.withBranch(branch)
211+
.withBranch(isNullOrEmpty(branchFromUrl) ? revision : branchFromUrl)
211212
.withTag(tag)
212213
.withDevfileFilenames(devfileFilenamesProvider.getConfiguredDevfileFilenames())
213214
.withServerUrl(serverUrl)

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,22 @@ protected void start() {
4040

4141
@Test(expectedExceptions = IllegalArgumentException.class)
4242
public void testParseInvalidUrl() {
43-
azureDevOpsURLParser.parse("http://www.eclipse.org");
43+
azureDevOpsURLParser.parse("http://www.eclipse.org", null);
44+
}
45+
46+
@Test
47+
public void shouldParseWithBranch() {
48+
AzureDevOpsUrl azureDevOpsUrl =
49+
azureDevOpsURLParser.parse("https://dev.azure.com/MyOrg/MyProject/_git/MyRepo", "branch");
50+
assertEquals(azureDevOpsUrl.getBranch(), "branch");
51+
}
52+
53+
@Test
54+
public void shouldParseWithUrlBranch() {
55+
AzureDevOpsUrl azureDevOpsUrl =
56+
azureDevOpsURLParser.parse(
57+
"https://dev.azure-server.com/MyOrg/MyProject/_git/MyRepo?version=GBmain", "branch");
58+
assertEquals(azureDevOpsUrl.getBranch(), "main");
4459
}
4560

4661
@Test(dataProvider = "parsing")
@@ -51,7 +66,7 @@ public void testParse(
5166
String repository,
5267
String branch,
5368
String tag) {
54-
AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(url);
69+
AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(url, null);
5570

5671
assertEquals(azureDevOpsUrl.getOrganization(), organization);
5772
assertEquals(azureDevOpsUrl.getProject(), project);
@@ -68,7 +83,7 @@ public void testParseServer(
6883
String repository,
6984
String branch,
7085
String tag) {
71-
AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(url);
86+
AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(url, null);
7287

7388
assertEquals(azureDevOpsUrl.getOrganization(), organization);
7489
assertEquals(azureDevOpsUrl.getProject(), project);
@@ -362,7 +377,7 @@ public Object[][] expectedServerParsing() {
362377

363378
@Test(dataProvider = "url")
364379
public void testCredentials(String url, String organization, Optional<String> credentials) {
365-
AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(url);
380+
AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(url, null);
366381

367382
assertEquals(azureDevOpsUrl.getOrganization(), organization);
368383
assertEquals(azureDevOpsUrl.getCredentials(), credentials);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void checkDevfileLocation(String repoUrl, String fileUrl) {
4444

4545
AzureDevOpsUrl azureDevOpsUrl =
4646
azureDevOpsURLParser
47-
.parse(repoUrl)
47+
.parse(repoUrl, null)
4848
.withDevfileFilenames(Arrays.asList("devfile.yaml", "foo.bar"));
4949
assertEquals(azureDevOpsUrl.devfileFileLocations().size(), 2);
5050
Iterator<RemoteFactoryUrl.DevfileLocation> iterator =
@@ -59,7 +59,7 @@ public void checkDevfileLocationServer(String repoUrl, String fileUrl) {
5959

6060
AzureDevOpsUrl azureDevOpsUrl =
6161
azureDevOpsURLParser
62-
.parse(repoUrl)
62+
.parse(repoUrl, null)
6363
.withDevfileFilenames(Arrays.asList("devfile.yaml", "foo.bar"));
6464
assertEquals(azureDevOpsUrl.devfileFileLocations().size(), 2);
6565
Iterator<RemoteFactoryUrl.DevfileLocation> iterator =
@@ -223,13 +223,13 @@ public static Object[][] urlsProviderServer() {
223223

224224
@Test(dataProvider = "repoProvider")
225225
public void checkRepositoryLocation(String rawUrl, String repoUrl) {
226-
AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(rawUrl);
226+
AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(rawUrl, null);
227227
assertEquals(azureDevOpsUrl.getRepositoryLocation(), repoUrl);
228228
}
229229

230230
@Test(dataProvider = "repoProviderServer")
231231
public void checkRepositoryLocationServer(String rawUrl, String repoUrl) {
232-
AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(rawUrl);
232+
AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(rawUrl, null);
233233
assertEquals(azureDevOpsUrl.getRepositoryLocation(), repoUrl);
234234
}
235235

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2024 Red Hat, Inc.
2+
* Copyright (c) 2012-2025 Red Hat, Inc.
33
* This program and the accompanying materials are made
44
* available under the terms of the Eclipse Public License 2.0
55
* which is available at https://www.eclipse.org/legal/epl-2.0/
@@ -11,6 +11,7 @@
1111
*/
1212
package org.eclipse.che.api.factory.server.bitbucket;
1313

14+
import static org.eclipse.che.api.factory.shared.Constants.REVISION_PARAMETER_NAME;
1415
import static org.eclipse.che.api.factory.shared.Constants.URL_PARAMETER_NAME;
1516
import static org.eclipse.che.dto.server.DtoFactory.newDto;
1617

@@ -94,7 +95,9 @@ public FactoryMetaDto createFactory(@NotNull final Map<String, String> factoryPa
9495

9596
// no need to check null value of url parameter as accept() method has performed the check
9697
final BitbucketServerUrl bitbucketServerUrl =
97-
bitbucketURLParser.parse(factoryParameters.get(URL_PARAMETER_NAME));
98+
bitbucketURLParser.parse(
99+
factoryParameters.get(URL_PARAMETER_NAME),
100+
factoryParameters.get(REVISION_PARAMETER_NAME));
98101
// create factory from the following location if location exists, else create default factory
99102
return createFactory(
100103
factoryParameters,
@@ -135,6 +138,6 @@ public FactoryDevfileV2Dto visit(FactoryDevfileV2Dto factoryDto) {
135138

136139
@Override
137140
public RemoteFactoryUrl parseFactoryUrl(String factoryUrl) throws ApiException {
138-
return bitbucketURLParser.parse(factoryUrl);
141+
return bitbucketURLParser.parse(factoryUrl, null);
139142
}
140143
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2023 Red Hat, Inc.
2+
* Copyright (c) 2012-2025 Red Hat, Inc.
33
* This program and the accompanying materials are made
44
* available under the terms of the Eclipse Public License 2.0
55
* which is available at https://www.eclipse.org/legal/epl-2.0/
@@ -47,7 +47,7 @@ public boolean accept(String repository) {
4747
@Override
4848
public String fileContent(String repository, String filePath) throws ApiException {
4949

50-
BitbucketServerUrl bitbucketServerUrl = bitbucketURLParser.parse(repository);
50+
BitbucketServerUrl bitbucketServerUrl = bitbucketURLParser.parse(repository, null);
5151

5252
try {
5353
return fetchContent(bitbucketServerUrl, filePath, false);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ private Optional<Matcher> getPatternMatcherByUrl(String url) {
182182
* https://bitbucket.apps.cluster-cb82.cb82.example.opentlc.com/scm/test/test1.git into
183183
* BitbucketUrl objects.
184184
*/
185-
public BitbucketServerUrl parse(String url) {
185+
public BitbucketServerUrl parse(String url, @Nullable String revision) {
186186

187187
if (bitbucketUrlPatterns.isEmpty()) {
188188
Optional<Matcher> matcherOptional = getPatternMatcherByUrl(url);
189189
if (matcherOptional.isPresent()) {
190-
return parse(matcherOptional.get());
190+
return parse(matcherOptional.get(), revision);
191191
}
192192
throw new UnsupportedOperationException(
193193
"The Bitbucket integration is not configured properly and cannot be used at this moment."
@@ -205,10 +205,10 @@ public BitbucketServerUrl parse(String url) {
205205
format(
206206
"The given url %s is not a valid Bitbucket server URL. Check either URL or server configuration.",
207207
url)));
208-
return parse(matcher).withUrl(url);
208+
return parse(matcher, revision).withUrl(url);
209209
}
210210

211-
private BitbucketServerUrl parse(Matcher matcher) {
211+
private BitbucketServerUrl parse(Matcher matcher, @Nullable String revision) {
212212
String scheme = matcher.group("scheme");
213213
String host = matcher.group("host");
214214
String port = null;
@@ -225,9 +225,9 @@ private BitbucketServerUrl parse(Matcher matcher) {
225225
project = matcher.group("project");
226226
}
227227
String repoName = matcher.group("repo");
228-
String branch = null;
228+
String branchFromUrl = null;
229229
try {
230-
branch = matcher.group("branch");
230+
branchFromUrl = matcher.group("branch");
231231
} catch (IllegalArgumentException e) {
232232
// keep branch with null, as the pattern doesn't have the branch group
233233
}
@@ -239,7 +239,7 @@ private BitbucketServerUrl parse(Matcher matcher) {
239239
.withProject(project)
240240
.withUser(user)
241241
.withRepository(repoName)
242-
.withBranch(branch)
242+
.withBranch(isNullOrEmpty(branchFromUrl) ? revision : branchFromUrl)
243243
.withDevfileFilenames(devfileFilenamesProvider.getConfiguredDevfileFilenames());
244244
}
245245
}

0 commit comments

Comments
 (0)