Skip to content

Commit a7d811c

Browse files
committed
commit
1 parent f74ac9f commit a7d811c

File tree

13 files changed

+215
-75
lines changed

13 files changed

+215
-75
lines changed

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,7 @@ public class AzureDevOpsURLParser {
5555
"^git@ssh\\.%s:v3/(?<organization>.*)/(?<project>.*)/(?<repoName>.*)$";
5656
private final String azureSSHDevOpsServerPatternTemplate =
5757
"^ssh://%s:22/(?<organization>.*)/(?<project>.*)/_git/(?<repoName>.*)$";
58-
private final String azureDevOpsPatternTemplate =
59-
"^https?://(?<organizationCanIgnore>[^@]++)?@?%s/(?<organization>[^/]++)/((?<project>[^/]++)/)?_git/"
60-
+ "(?<repoName>[^?]++)"
61-
+ "([?&]path=(?<path>[^&]++))?"
62-
+ "([?&]version=GT(?<tag>[^&]++))?"
63-
+ "([?&]version=GB(?<branch>[^&]++))?"
64-
+ "(.*)";
58+
private final String azureDevOpsPatternTemplate;
6559
private static final String PROVIDER_NAME = "azure-devops";
6660

6761
@Inject
@@ -74,6 +68,13 @@ public AzureDevOpsURLParser(
7468
this.tokenManager = tokenManager;
7569
this.azureDevOpsScmApiEndpointHost =
7670
trimEnd(azureDevOpsScmApiEndpoint, '/').replaceFirst("https?://", "");
71+
azureDevOpsPatternTemplate =
72+
"^https?://(?<organizationCanIgnore>[^@]++)?@?%s/(?<organization>[^/]++)/((?<project>[^/]++)/)?_git/"
73+
+ "(?<repoName>[^?]++)"
74+
+ "([?&]path=(?<path>[^&]++))?"
75+
+ "([?&]version=GT(?<tag>[^&]++))?"
76+
+ "([?&]version=GB(?<branch>[^&]++))?"
77+
+ "(.*)";
7778
this.azureDevOpsPattern =
7879
compile(format(azureDevOpsPatternTemplate, azureDevOpsScmApiEndpointHost));
7980
this.azureSSHDevOpsPattern =
@@ -178,12 +179,14 @@ public AzureDevOpsUrl parse(String url) {
178179

179180
String branch = null;
180181
String tag = null;
182+
String path = null;
181183

182184
String organization = matcher.group("organization");
183185
String urlToReturn = url;
184186
if (isHTTPSUrl) {
185187
branch = matcher.group("branch");
186188
tag = matcher.group("tag");
189+
path = matcher.group("path");
187190
// The url might have the following formats:
188191
// - https://<organization>@<host>/<organization>/<project>/_git/<repoName>
189192
// - https://<credentials>@<host>/<organization>/<project>/_git/<repoName>
@@ -206,6 +209,7 @@ public AzureDevOpsUrl parse(String url) {
206209
.withOrganization(organization)
207210
.withBranch(branch)
208211
.withTag(tag)
212+
.withPath(path)
209213
.withDevfileFilenames(devfileFilenamesProvider.getConfiguredDevfileFilenames())
210214
.withServerUrl(serverUrl)
211215
.withUrl(urlToReturn);

Diff for: wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsUrl.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class AzureDevOpsUrl extends DefaultFactoryUrl {
4545

4646
private String serverUrl;
4747

48+
private String path;
49+
4850
private final List<String> devfileFilenames = new ArrayList<>();
4951

5052
protected AzureDevOpsUrl() {}
@@ -100,6 +102,15 @@ public AzureDevOpsUrl withBranch(String branch) {
100102
return this;
101103
}
102104

105+
public String getPath() {
106+
return path;
107+
}
108+
109+
public AzureDevOpsUrl withPath(String path) {
110+
this.path = path;
111+
return this;
112+
}
113+
103114
@Override
104115
public String getProviderUrl() {
105116
return isNullOrEmpty(serverUrl) ? "https://" + hostName : serverUrl;
@@ -148,7 +159,12 @@ public String rawFileLocation(String fileName) {
148159
.add(repository)
149160
.add(
150161
"items"
151-
+ String.format("?path=/%s", fileName)
162+
+ "?path="
163+
+ (isNullOrEmpty(path) ? "" : path)
164+
+ "%2F"
165+
+ (path.endsWith(fileName)
166+
? path.substring(0, path.indexOf(fileName) - 1)
167+
: fileName)
152168
+ (!isNullOrEmpty(branch)
153169
? String.format("&versionType=branch&version=%s", branch)
154170
: "")

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

+43-8
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@ public void testParse(
5050
String project,
5151
String repository,
5252
String branch,
53-
String tag) {
53+
String tag,
54+
String path) {
5455
AzureDevOpsUrl azureDevOpsUrl = azureDevOpsURLParser.parse(url);
5556

5657
assertEquals(azureDevOpsUrl.getOrganization(), organization);
5758
assertEquals(azureDevOpsUrl.getProject(), project);
5859
assertEquals(azureDevOpsUrl.getRepository(), repository);
5960
assertEquals(azureDevOpsUrl.getBranch(), branch);
6061
assertEquals(azureDevOpsUrl.getTag(), tag);
62+
assertEquals(azureDevOpsUrl.getPath(), path);
6163
}
6264

6365
@Test(dataProvider = "parsingServer")
@@ -86,6 +88,7 @@ public Object[][] expectedParsing() {
8688
"MyProject",
8789
"MyRepo",
8890
null,
91+
null,
8992
null
9093
},
9194
{
@@ -94,6 +97,7 @@ public Object[][] expectedParsing() {
9497
"MyProject",
9598
"MyRepo.git",
9699
null,
100+
null,
97101
null
98102
},
99103
{
@@ -102,6 +106,7 @@ public Object[][] expectedParsing() {
102106
"MyProject",
103107
"MyRepo.dot.git",
104108
null,
109+
null,
105110
null
106111
},
107112
{
@@ -110,6 +115,7 @@ public Object[][] expectedParsing() {
110115
"MyProject",
111116
"MyRepo",
112117
null,
118+
null,
113119
null
114120
},
115121
{
@@ -118,15 +124,17 @@ public Object[][] expectedParsing() {
118124
"MyProject",
119125
"MyRepo-with-hypen",
120126
null,
127+
null,
121128
null
122129
},
123-
{"https://dev.azure.com/MyOrg/MyProject/_git/-", "MyOrg", "MyProject", "-", null, null},
130+
{"https://dev.azure.com/MyOrg/MyProject/_git/-", "MyOrg", "MyProject", "-", null, null, null},
124131
{
125132
"https://dev.azure.com/MyOrg/MyProject/_git/-j.git",
126133
"MyOrg",
127134
"MyProject",
128135
"-j.git",
129136
null,
137+
null,
130138
null
131139
},
132140
{
@@ -135,14 +143,16 @@ public Object[][] expectedParsing() {
135143
"MyProject",
136144
"MyRepo",
137145
"main",
138-
null
146+
null,
147+
"MyFile",
139148
},
140149
{
141150
"[email protected]:v3/MyOrg/MyProject/MyRepo",
142151
"MyOrg",
143152
"MyProject",
144153
"MyRepo",
145154
null,
155+
null,
146156
null
147157
},
148158
{
@@ -151,6 +161,7 @@ public Object[][] expectedParsing() {
151161
"MyProject",
152162
"MyRepo.git",
153163
null,
164+
null,
154165
null
155166
},
156167
{
@@ -159,6 +170,7 @@ public Object[][] expectedParsing() {
159170
"MyProject",
160171
"MyRepo.dot.git",
161172
null,
173+
null,
162174
null
163175
},
164176
{
@@ -167,6 +179,7 @@ public Object[][] expectedParsing() {
167179
"MyProject",
168180
"MyRepo",
169181
null,
182+
null,
170183
null
171184
},
172185
{
@@ -175,15 +188,17 @@ public Object[][] expectedParsing() {
175188
"MyProject",
176189
"MyRepo-with-hypen",
177190
null,
191+
null,
178192
null
179193
},
180-
{"[email protected]:v3/MyOrg/MyProject/-", "MyOrg", "MyProject", "-", null, null},
194+
{"[email protected]:v3/MyOrg/MyProject/-", "MyOrg", "MyProject", "-", null, null, null},
181195
{
182196
"[email protected]:v3/MyOrg/MyProject/-j.git",
183197
"MyOrg",
184198
"MyProject",
185199
"-j.git",
186200
null,
201+
null,
187202
null
188203
},
189204
{
@@ -192,25 +207,45 @@ public Object[][] expectedParsing() {
192207
"MyProject",
193208
"MyRepo",
194209
"main",
195-
null
210+
null,
211+
"MyFile"
196212
},
197213
{
198214
"https://[email protected]/MyOrg/MyProject/_git/MyRepo?path=MyFile&version=GTMyTag&_a=contents",
199215
"MyOrg",
200216
"MyProject",
201217
"MyRepo",
202218
null,
203-
"MyTag"
219+
"MyTag",
220+
"MyFile"
204221
},
205222
{
206223
"https://[email protected]/MyOrg/MyProject/_git/MyRepo?path=MyFile&version=GTMyTag",
207224
"MyOrg",
208225
"MyProject",
209226
"MyRepo",
210227
null,
211-
"MyTag"
228+
"MyTag",
229+
"MyFile"
230+
},
231+
{
232+
"https://[email protected]/MyOrg/MyProject/_git/MyRepo?path=/path/to/MyFile&version=GTMyTag",
233+
"MyOrg",
234+
"MyProject",
235+
"MyRepo",
236+
null,
237+
"MyTag",
238+
"/path/to/MyFile"
239+
},
240+
{
241+
"https://[email protected]/MyOrg/_git/MyRepo",
242+
"MyOrg",
243+
"MyRepo",
244+
"MyRepo",
245+
null,
246+
null,
247+
null
212248
},
213-
{"https://[email protected]/MyOrg/_git/MyRepo", "MyOrg", "MyRepo", "MyRepo", null, null},
214249
};
215250
}
216251

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ public class BitbucketServerURLParser {
5353
private static final List<String> bitbucketUrlPatternTemplates =
5454
List.of(
5555
"^(?<scheme>%s)://(?<host>%s)/scm/~(?<user>[^/]+)/(?<repo>.*).git$",
56-
"^(?<scheme>%s)://(?<host>%s)/users/(?<user>[^/]+)/repos/(?<repo>[^/]+)/browse(\\?at=(?<branch>.*))?",
56+
"^(?<scheme>%s)://(?<host>%s)/users/(?<user>[^/]+)/repos/(?<repo>[^/]+)/browse((/(?<path>.+?))?(\\?at=(?<branch>.+))?)$",
5757
"^(?<scheme>%s)://(?<host>%s)/users/(?<user>[^/]+)/repos/(?<repo>[^/]+)/?",
5858
"^(?<scheme>%s)://(?<host>%s)/scm/(?<project>[^/~]+)/(?<repo>[^/]+).git",
59-
"^(?<scheme>%s)://(?<host>%s)/projects/(?<project>[^/]+)/repos/(?<repo>[^/]+)/browse(\\?at=(?<branch>.*))?",
59+
"^(?<scheme>%s)://(?<host>%s)/projects/(?<project>[^/]+)/repos/(?<repo>[^/]+)/browse((/(?<path>.+?))?(\\?at=(?<branch>.+))?)$",
6060
"^(?<scheme>%s)://git@(?<host>%s):(?<port>\\d*)/~(?<user>[^/]+)/(?<repo>.*).git$",
6161
"^(?<scheme>%s)://git@(?<host>%s):(?<port>\\d*)/(?<project>[^/]+)/(?<repo>.*).git$");
6262
private final List<Pattern> bitbucketUrlPatterns = new ArrayList<>();
@@ -224,11 +224,17 @@ private BitbucketServerUrl parse(Matcher matcher) {
224224
}
225225
String repoName = matcher.group("repo");
226226
String branch = null;
227+
String path = null;
227228
try {
228229
branch = matcher.group("branch");
229230
} catch (IllegalArgumentException e) {
230231
// keep branch with null, as the pattern doesn't have the branch group
231232
}
233+
try {
234+
path = matcher.group("path");
235+
} catch (IllegalArgumentException e) {
236+
// keep branch with null, as the pattern doesn't have the branch group
237+
}
232238

233239
return new BitbucketServerUrl()
234240
.withScheme(scheme)
@@ -238,6 +244,7 @@ private BitbucketServerUrl parse(Matcher matcher) {
238244
.withUser(user)
239245
.withRepository(repoName)
240246
.withBranch(branch)
247+
.withPath(path)
241248
.withDevfileFilenames(devfileFilenamesProvider.getConfiguredDevfileFilenames());
242249
}
243250
}

Diff for: wsmaster/che-core-api-factory-bitbucket-server/src/main/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketServerUrl.java

+11-2
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/
@@ -43,6 +43,8 @@ public class BitbucketServerUrl extends DefaultFactoryUrl {
4343
/** Branch name */
4444
private String branch;
4545

46+
private String path;
47+
4648
/** Devfile filenames list */
4749
private final List<String> devfileFilenames = new ArrayList<>();
4850

@@ -141,6 +143,13 @@ protected BitbucketServerUrl withBranch(String branch) {
141143
return this;
142144
}
143145

146+
protected BitbucketServerUrl withPath(String path) {
147+
if (!isNullOrEmpty(path)) {
148+
this.path = path;
149+
}
150+
return this;
151+
}
152+
144153
/**
145154
* Gets user of this bitbucket server url
146155
*
@@ -196,7 +205,7 @@ public String rawFileLocation(String fileName) {
196205
.add("repos")
197206
.add(repository)
198207
.add("raw")
199-
.add(fileName);
208+
.add(isNullOrEmpty(path) ? fileName : path);
200209
String resultUrl = joiner.toString();
201210
if (branch != null) {
202211
resultUrl = resultUrl + "?at=" + branch;

0 commit comments

Comments
 (0)