Skip to content

Commit 59b10ad

Browse files
authored
Respect Bitbucket Server urls with branch in format /refs/heads/<branchname> (#861)
* respect Bitbucket Server urls with branch in format /refs/heads/<branchname> * fixup! respect Bitbucket Server urls with branch in format /refs/heads/<branchname>
1 parent 8eb4406 commit 59b10ad

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ private BitbucketServerUrl parse(Matcher matcher, @Nullable String revision) {
227227
String repoName = matcher.group("repo");
228228
String branchFromUrl = null;
229229
try {
230-
branchFromUrl = matcher.group("branch");
230+
String branch = matcher.group("branch");
231+
branchFromUrl =
232+
branch.startsWith("refs/heads/")
233+
? branch.substring(11)
234+
: (branch.startsWith("refs%2Fheads%2F") ? branch.substring(15) : branch);
231235
} catch (IllegalArgumentException e) {
232236
// keep branch with null, as the pattern doesn't have the branch group
233237
}

wsmaster/che-core-api-factory-bitbucket-server/src/test/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketServerURLParserTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,21 @@ public Object[][] expectedParsing() {
248248
null,
249249
"project",
250250
"test1",
251-
"refs%2Fheads%2Fbranch"
251+
"branch"
252252
},
253253
{
254254
"https://bbkt.com/projects/project/repos/test1/browse?at=refs%2Fheads%2Fbranch",
255255
null,
256256
"project",
257257
"test1",
258-
"refs%2Fheads%2Fbranch"
258+
"branch"
259+
},
260+
{
261+
"https://bitbucket.2mcl.com/users/user/repos/repo/browse?at=refs/heads/branch",
262+
"user",
263+
null,
264+
"repo",
265+
"branch"
259266
},
260267
{"https://bbkt.com/users/user/repos/repo/", "user", null, "repo", null}
261268
};

0 commit comments

Comments
 (0)